convert string of numbers to array javascript code example

Example 1: how to convert string to int a array in javascript

var a = "1,2,3,4";

var b = a.split(',').map(function(item) {
    return parseInt(item, 10);
});

Example 2: javascript Convert an array of strings to numbers

const toNumbers = arr => arr.map(Number);
toNumbers(['1', '2', '3','4']);     // [1, 2, 3, 4]

Example 3: convert array string to number

// CONVERT ARRAY STRING TO ARRAY NUMBER
const arrStr = ["1", "3", "5", "9"];
const nuevo = arrStr.map((i) => Number(i));
console.log(nuevo);
// [1,3,5,9];