9

I have a string that contains an array with numbers in square bracket like this [1, 2,3, 4]. I want convert that string into array of integers. I can use split function but I also need to strip of square brackets and remove spaces if any between the numbers.

1
  • Try match, then the input doesn't need to be valid JSON. Commented Feb 12, 2016 at 6:07

1 Answer 1

16

if you already have the string like this "[1, 2,3, 4]" JSON.parse will do

var arr = JSON.parse( "[1, 2,3, 4]" );
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.