将string数组转换为number数组
let x1 = ['1','2'];
console.log(x1);
//["1", "2"]
x1 = x1.map(Number);
console.log(x1);
//[1, 2]
将number数组转换为string数组
let x1 = [1,2];
console.log(x1);
//[1, 2]
x1 = x1.map(String);
console.log(x1);
//["1", "2"]
JS中string数组和number数组之间快速互转
阅读 50
2022-05-30
将string数组转换为number数组
let x1 = ['1','2'];
console.log(x1);
//["1", "2"]
x1 = x1.map(Number);
console.log(x1);
//[1, 2]
将number数组转换为string数组
let x1 = [1,2];
console.log(x1);
//[1, 2]
x1 = x1.map(String);
console.log(x1);
//["1", "2"]
相关推荐
精彩评论(0)