use split
& map
& parseInt
methods.
var numbers="15,14,12,13";
var result=numbers.split(',').map(function(number){
return parseInt(number);
});
console.log('convert '+JSON.stringify(numbers)+" to array:"+JSON.stringify(result));
Use eval
method
var numbers="15,14,12,13";
var result=eval("["+numbers+"]");
console.log('convert '+JSON.stringify(numbers)+" to array:"+JSON.stringify(result));
solved How to get numbers in a string separated with commas and save each of them in an Array in Javascript [duplicate]