How to convert a comma separated string of numbers to an array of integers in JavaScript

1 Answer

0 votes
var s = "0,1,2,3,4";

var arr = JSON.parse("[" + s + "]");

document.write(arr);


/*
run:
  
0,1,2,3,4 
   
*/

 



answered Mar 2, 2019 by avibootz
...