Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create line breaks in console.log() in node

Is there a way to get new lines in console.log when printing multiple objects?

Suppose we have console.log(a, b, c) where a, b, and c are objects. Is there a way to get a line break between the objects?

I tried console.log(a, '\n', b, '\n', c), but that does not work in Node.js.

like image 890
DCR Avatar asked Apr 04 '18 21:04

DCR


People also ask

How do you insert a line break in node JS?

The newline character is \n in JavaScript and many other languages. All you need to do is add \n character whenever you require a line break to add a new line to a string.

How does console log work in node?

log() function from console class of Node. js is used to display the messages on the console. It prints to stdout with newline. Parameter: This function contains multiple parameters which are to be printed.

Can you console log in node JS?

js provides a console module which provides tons of very useful ways to interact with the command line. It is basically the same as the console object you find in the browser. The most basic and most used method is console. log() , which prints the string you pass to it to the console.


1 Answers

Add \n (newline) between them:

console.log({ a: 1 }, '\n', { b: 3 }, '\n', { c: 3 })
like image 146
Ori Drori Avatar answered Oct 06 '22 21:10

Ori Drori