Amo*_*rni 7 node.js console.log
请考虑以下代码:
var myVar = 'This is my text.\nAnd other information.\rHow to console.log\n\r?';
console.log(myVar);
Run Code Online (Sandbox Code Playgroud)
输出:
This is my text.
And other information.
How to console.log
?
Run Code Online (Sandbox Code Playgroud)
我如何安慰\n,\r&\n\r?
小智 12
我发现自己JSON.stringify用来打印这样的东西.
码:
console.log(JSON.stringify("i am a string!\nwith some newlines\r\n!"));
Run Code Online (Sandbox Code Playgroud)
输出:
"i am a string!\nwith some newlines\r\n!"
Run Code Online (Sandbox Code Playgroud)
得到了一些解决方案:
代码:
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);
Run Code Online (Sandbox Code Playgroud)
输出:
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
?
Run Code Online (Sandbox Code Playgroud)
也欢迎其他方式。
| 归档时间: |
|
| 查看次数: |
7532 次 |
| 最近记录: |