Is there any way to force Chrome's JS console to display newlines like Firefox?
Chrome:
Firefox:
Possibly a hidden switch somewhere?
Is there any way to force Chrome's JS console to display newlines like Firefox?
Chrome:
Firefox:
Possibly a hidden switch somewhere?
Share Improve this question edited Oct 9, 2012 at 4:30 Blender asked Oct 9, 2012 at 4:17 BlenderBlender 298k55 gold badges458 silver badges510 bronze badges 5-
I suppose something like
x.replace(/\n/g,"\\n")
is out of the question? (Or use FF, which seems to do what you want by default.) – nnnnnn Commented Oct 9, 2012 at 4:19 - @nnnnnn: That's the behavior that I'm trying to emulate in Chrome. There doesn't seem to be a hidden switch anywhere, though. – Blender Commented Oct 9, 2012 at 4:24
-
Yeah, I figured. I guess worst-case if you need to copy-paste the value or something you could manually enter a
.replace()
statement as per my previous ment, or define a function to do it so you don't have to type it every time. (Clunky? Yes, I admit it.) – nnnnnn Commented Oct 9, 2012 at 4:32 - can you tell us how to display those characters in firefox? I'm around this issue for 20 minutes and I can't get by googling it a good answer for this problem – João Pimentel Ferreira Commented Jan 29, 2018 at 13:51
- @JoãoPimentelFerreira: Firefox stopped displaying strings like this starting with 23.0. – Blender Commented Jan 29, 2018 at 18:38
4 Answers
Reset to default 10You can use encodeURI
for showing the hidden stuffs.
Something like this encodeURI("a\nb")
instead of "a\nb"
.
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.
You can stringify the value to get these invisible characters:
> JSON.stringify("a\nb")
<- ""a\nb""
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./3rdpage/us/javaUnicode/converter.html