在Node.js中,是否有方法在控制台上打印\n\r?
考虑以下代码:在Node.js中,是否有方法在控制台上打印\n\r?,node.js,console.log,Node.js,Console.log,考虑以下代码: var myVar = 'This is my text.\nAnd other information.\rHow to console.log\n\r?'; console.log(myVar); 输出: This is my text. And other information. How to console.log ? 如何使用\n,\r和\n\r进行控制台操作?获得一些: 代码: var myVar = 'This is my text.\nAnd other i
var myVar = 'This is my text.\nAnd other information.\rHow to console.log\n\r?';
console.log(myVar);
输出:
This is my text.
And other information.
How to console.log
?
如何使用\n
,\r
和\n\r
进行控制台操作?获得一些:
代码:
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);
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
?
输出:
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);
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
?
其他方式也很受欢迎。我发现自己使用了
JSON.stringify
来打印这样的东西
代码:
console.log(JSON.stringify("i am a string!\nwith some newlines\r\n!"));
"i am a string!\nwith some newlines\r\n!"
输出:
console.log(JSON.stringify("i am a string!\nwith some newlines\r\n!"));
"i am a string!\nwith some newlines\r\n!"
据我所知,如果您在console.log中输出一些特殊字符 示例:%1实际上是控制台日志的控制字符,您必须将其URL编码为:%25 例如,因为%c对输出进行css格式化
换行符将不会显示为so这是一个老问题,但对于那些像我一样登陆此页面的人来说,一个更简单的解决方案就是用前面的“\”跳过delimeter