经过一些操作后,我得到一个数组。我需要将所有数组值转换为整数。
我的示例代码
var result_string = 'a,b,c,d|1,2,3,4';
result = result_string.split("|");
alpha = result[0];
count = result[1];
// console.log(alpha);
// console.log(count);
count_array = count.split(",");
count_array现在包含,1,2,3,4但我需要这些值为整数。
我曾经使用过parseInt(count_array);,但是失败了。JS将此数组中的每个值视为字符串。
parseInt("8foo", 10)return8而+"8foo"returnNaN。我喜欢您的方法,实际上对无效数字更严格。