1

The problem is quite simple. I would like to convert a 2d array to a string and preserve the brackets. How can I do that? The String() method will remove all the brackets, unfortunately.

Example: [[21, 21], [19, -2]] should be converted to "[[21, 21], [19, -2]]"

Do I need to build a for-loop to do that or is there built-in method or something similar I can use?

Thank you

1
  • 7
    Have you tried JSON.stringify(yourArray)? Commented Oct 24, 2019 at 10:45

1 Answer 1

3

Try

let a = [[21, 21], [19, -2]] ;

console.log( JSON.stringify(a) );

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

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.