Display control characters in the Chrome console?

Is there a way to get the Chrome JS console to display newlines like Firefox?

Chrome:

enter image description here

Firefox:

enter image description here

Perhaps a hidden switch somewhere?

+4
source share
4 answers

You can use encodeURI to display hidden content.

Something like encodeURI("a\nb") instead of "a\nb" .

Chrome EncodeURI

+8
source

In node.js, require("util").inspect does something very similar. I could not find the equivalent of a browser, although, fortunately, the node.js implementation is pretty straight forward:

 JSON.stringify(value) .replace(/^"|"$/g, '') .replace(/'/g, "\\'") .replace(/\\"/g, '"') ; 

In your case, just JSON.stringify(value) should work.

Hope this helps.

+2
source

You can try this way

 var x = 'a\\nb'; 

EDIT:

You can use the hexadecimal character in the string.

 \ = '\u005C' > var x = 'a\u005Cnb'; > x <- "a\nb" > x === "a\nb" is false. > x === "a\\nb" is true or x === 'a\u005Cnb' is true. 

You can see the links.

http://mathiasbynens.be/notes/javascript-escapes http://code.cside.com/3rdpage/us/javaUnicode/converter.html

0
source

You can convert the value to a string to get these invisible characters:

 > JSON.stringify("a\nb") <- ""a\nb"" 
0
source

Source: https://habr.com/ru/post/1438548/


All Articles