Reputation: 183
I would like to output:
[2, [23]]
however, when I run:
console.log([2,[23]]);
I get:
(2) [1, Array(1)]
I have tried to use the toString()
method, but I got '2,23'
instead.
Upvotes: 3
Views: 63
Reputation: 1073968
You can't get the exact same representation (not least because it varies from environment to environment), but JSON.stringify
will get close:
var s = JSON.stringify([2,[23]]); // s gets "[2,[23]]"
document.body.appendChild(
document.createTextNode(s)
);
Upvotes: 5