Slayjay
Slayjay

Reputation: 3

JavaScript Get nested array (1 level) with quotes preserving numbers with console.log

How can I take something in the form of

[["[]",2,"c"],["d","e","f"]]

and log

[["[]","2","c"],["d","e","f"]]

to the console? I have tried console.log(array.toString()) but that just logs

[[[],2,c],[d,e,f]]

Upvotes: 0

Views: 138

Answers (3)

Kyle
Kyle

Reputation: 1503

This will preserve the arrays and only turn the the inner array items into strings.

var data = [["[]",2,"c"],["d","e","f"]];
var stringed = data.map((d)=>{
  return (d.toString().split(","))
});
console.log(stringed);

Upvotes: 0

kamal sehrawat
kamal sehrawat

Reputation: 131

If u want to preserve double quotes " then you can use

console.log(${'[["[]",2,"c"],["d","e","f"]]'})

else u can use

console.log(JSON.stringify([["[]",2,"c"],["d","e","f"]]))

Upvotes: 0

Teiem
Teiem

Reputation: 1629

You can use JSON.stringify and log that

console.log(JSON.stringify([["[]",2,"c"],["d","e","f"]]))

Upvotes: 3

Related Questions