How to Convert String with comma to Array in Javascript - es6
Convert string with commas to array using the split() Method
lets assume we have a variable string where values are comma separated. we will split this by the comma, and then store it in an array.
var numStr = "1, 5, 8";
var numArr = numStr.split(",");
// result numArr = ["1", "5","8"]
this split numStr from ',' and convert in an array
if you want numbers in array: [1, 5, 8]
var numArr = str.split(',').map(Number);
Comments