I need to convert a string with multiple numbers to an array in jQuery. My string is the one below:
var strVal = "901,235,342,421,345,745,544,324,445,123,232,986,345,678";
I need to convert a string with multiple numbers to an array in jQuery. My string is the one below:
var strVal = "901,235,342,421,345,745,544,324,445,123,232,986,345,678";
You don't need jquery for this
var strVal = "901,235,342,421,345,745,544,324,445,123,232,986,345,678";
var result = strVal.split(",").map(x=>+x);
console.log(result);
You could use String.split
with ','
and then Array#map
with to Number
converted values
var strVal = "901,235,342,421,345,745,544,324,445,123,232,986,345,678",
numbers = strVal.split(',').map(Number);
console.log(numbers);
.as-console-wrapper { max-height: 100% !important; top: 0; }