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.
Asked
Active
Viewed 1.0k times
1 Answers
15
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
- 66,980
- 10
- 72
- 94