2

I have a string as a prototype of an array if arrays:

'[ [7,8,9], [12,13,14] ]'

Are there any solutions to convert this to array of arrays?

I have used Array.from() with no luck.

1
  • 12
    Use JSON.parse() Commented Aug 18, 2020 at 20:40

3 Answers 3

1

You can use eval (usually not recommended):

let str = '[ [7,8,9], [12,13,14] ]';
let arr = eval(str);
console.log(arr);

Or JSON.parse:

let str = '[ [7,8,9], [12,13,14] ]';
let arr = JSON.parse(str);
console.log(arr);

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

Comments

0

The easiest way is to use eval but you know: eval is evil because it could be harmfull and should normally not be used.

let str = '[ [7,8,9], [12,13,14] ]';

eval('arr='+str+';');
console.log(arr);

Comments

0

You can use JSON.parse() Its parse string to JS object.

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.