2013-06-27 40 views

回答

9

我發現自己使用JSON.stringify來打印這樣的東西。

代碼:

console.log(JSON.stringify("i am a string!\nwith some newlines\r\n!")); 

輸出:

"i am a string!\nwith some newlines\r\n!" 
2

得到了一些solution

代碼

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 
? 

其它方式也受到了歡迎。

0

據我知道,如果你輸出你的console.log一些特殊字符

例如:%實際上是控制檯日誌的控制字符,您必須將其編碼爲:%25

因爲%C做你的輸出的CSS格式化,作爲一個例子

的換行符將不被顯示爲這樣

相關問題