7

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.

Jazz
  • 127
  • 1
  • 5
  • Try [*match*](http://www.ecma-international.org/ecma-262/6.0/#sec-string.prototype.match), then the input doesn't need to be valid JSON. – RobG Feb 12 '16 at 06:07

1 Answers1

11

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

var arr = JSON.parse( "[1, 2,3, 4]" );
gurvinder372
  • 64,240
  • 8
  • 67
  • 88