Blender
Blender

Reputation: 298196

Displaying control characters in Chrome's console?

Is there any way to force Chrome's JS console to display newlines like Firefox?

Chrome:

enter image description here

Firefox:

enter image description here

Possibly a hidden switch somewhere?

Upvotes: 7

Views: 6401

Answers (4)

Xavi
Xavi

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

Thomas Hickman
Thomas Hickman

Reputation: 165

You can stringify the value to get these invisible characters:

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

Upvotes: 1

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167182

You can use encodeURI for showing the hidden stuffs.

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

Chrome EncodeURI

Upvotes: 10

Sinan AKYAZICI
Sinan AKYAZICI

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

Related Questions