0

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";
user7393973
  • 2,118
  • 1
  • 15
  • 51
ziel
  • 117
  • 1
  • 10

2 Answers2

2

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; }
Nina Scholz
  • 351,820
  • 24
  • 303
  • 358
1

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);
Vladu Ionut
  • 7,765
  • 1
  • 17
  • 30