I simply have a huge array in a string like this:
"test", "blabla", "anothertest", "et", "cetera"
I need to be able to convert it to an array, preferable without the " "'s still left over. I have no idea how javascript would be able to do this, but I heard JSON was able to do something like this.
2 Answers 2
JSON is fine indeed:
var string = '"test", "blabla", "anothertest", "et", "cetera"';
JSON.parse('[' + string + ']');
Keep in mind that string must respect the JSON syntax. More precisely, you have to check that double quotes are used, the separator is a comma and so on.
Comments
If your string contains data in quotes, and separated with comma, it almost valid json. Just do this
var myparsedarray = JSON.parse("[" + yourstring + "]");