I have a multidimensional array in javascript that I would like to be able to turn into a string while preserving brackets. I have taken a look at other questions such as javascript - Convert array to string while preserving brackets and the answers there didn't help me much.
My array could look like the following:
[[[0,0,1],1],[[1,0,0],4],[[1,0,1],5], [[0,1,1],3],[[1,1,0],6],[[0,1,0],2]]
When I print the array I see:
0,0,1,1,1,0,0,4,1,0,1,5,0,1,1,3,1,1,0,6,0,1,0,2
The output that I am expecting is what the original array looks like.
I have also tried the following code:
alert("[[" + myArray.join("],[") + "]]");
This works for almost everything, I get an output of:
[[0,0,1,1],[1,0,0,4],[1,0,1,5], ...
And I would like to see what the origional array looks like with the brackets. I would also like to stay away from JSON.stringify(); and JSON.parse();
JSON.stringify?BFSfunction.JSON.stringifywould provide exactly what you are looking for, being able to see what the array looks like with the brackets. Why the avoidance ofJSON.stringify?JSON.stringify()andJSON.parse()is literally what you're describing.JSON.parseon a stringified array will convert it back to an array (using a simple nested array with 0 in it):Array.isArray(JSON.parse(JSON.stringify([[0]])))