我需要将具有多个数字的字符串转换为jQuery中的数组。我的字符串如下:
var strVal = "901,235,342,421,345,745,544,324,445,123,232,986,345,678";
答案 0 :(得分:2)
您可以将String.split
与','
一起使用,然后将Array#map
与Number
转化后的值
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; }

答案 1 :(得分:1)
这个
你不需要jquery
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);