1

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

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

If your string contains data in quotes, and separated with comma, it almost valid json. Just do this

var myparsedarray = JSON.parse("[" + yourstring + "]");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.