2

I am trying to turn a string like:

"[["firstVal","secondVal"],["firstVal","secondVal"]]"

Into a javascript array (It is a 2D array)

Is there a way that I can do this using javascript or jQuery?

Many Thanks!

1

2 Answers 2

6

You can use JSON.parse to achieve what you require:

var str = '[["firstVal","secondVal"],["firstVal","secondVal"]]';
var arr = JSON.parse(str);
console.log(arr);

Note that I had to amend the outer quotes to ' as your example string is malformed.

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

1 Comment

Thank you! I will accept your answer as soon as I can
1

Use JSON.parse() method to do that :

JSON.parse('[["firstVal","secondVal"],["firstVal","secondVal"]]');

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.