In Node.js is there any way to print the \n \r on console?
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.
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!"