If I have this below as a string, how can I easily make that into an array?
"[[0.01,4.99,0.01],[5,14.95,0.05]]"
I want the same result as:
var x = [[0.01,4.99,0.01],[5,14.95,0.05]];
var x = JSON.parse("[[0.01,4.99,0.01],[5,14.95,0.05]]");
Or the way jQuery does JSON parsing (better than eval
):
var x = (new Function("return " + "[[0.01,4.99,0.01],[5,14.95,0.05]]"))();
To make this answer complete, you can use a polyfill for older browsers to support JSON.parse
and JSON.stringify
. I recommend json3, because Crockfords json2 is to crockfordy (insiders know what I mean).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With