Consider, the following code:
var myVar = 'This is my text.\nAnd other information.\rHow to console.log\n\r?';
console.log(myVar);
Output:
This is my text.
And other information.
How to console.log
?
How can I console with the \n
, \r
& \n\r
?
If you wish to add a new line to the JavaScript new line console while printing a few words, the \n sign for the new line can be used.
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.
But sometimes we may need to print the console without trailing newline. In that case, we can use process. stdout. write() method to print to console without trailing newline.
I find myself using JSON.stringify
to print things like this.
Code:
console.log(JSON.stringify("i am a string!\nwith some newlines\r\n!"));
Output:
"i am a string!\nwith some newlines\r\n!"
Got some solution:
Code:
var myVar = 'This is my text.\nAnd other information.\rHow to console.log\n\r?';
console.log(require('util').inspect(myVar, { showHidden: true, depth: null }));
console.log('----------------');
console.log('Just console.log');
console.log(myVar);
Output:
This is my text.\nAnd other information.\rHow to console.log\n\r?
----------------
Just console.log
This is my text.
And other information.
How to console.log
?
Other ways are also welcomed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With