Reputation: 298196
Is there any way to force Chrome's JS console to display newlines like Firefox?
Chrome:
Firefox:
Possibly a hidden switch somewhere?
Upvotes: 7
Views: 6401
Reputation: 20439
In node.js, require("util").inspect
does something very similar. I haven't been able to find a browser equivalent, though fortunately the node.js implementation is fairly straight forward:
JSON.stringify(value)
.replace(/^"|"$/g, '')
.replace(/'/g, "\\'")
.replace(/\\"/g, '"')
;
In your case, just JSON.stringify(value)
should work.
Upvotes: 2
Reputation: 165
You can stringify the value to get these invisible characters:
> JSON.stringify("a\nb")
<- ""a\nb""
Upvotes: 1
Reputation: 167182
You can use encodeURI
for showing the hidden stuffs.
Something like this encodeURI("a\nb")
instead of "a\nb"
.
Upvotes: 10
Reputation: 3952
You can try this way
var x = 'a\\nb';
EDIT:
You can use hexadecimal character in 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 take a look at links.
http://mathiasbynens.be/notes/javascript-escapes http://code.cside.com/3rdpage/us/javaUnicode/converter.html
Upvotes: 0