JS中数组快速转换成Number类型或String类型

1.将string数组转换为number数组 
 

let x1 = ['1','2'];
console.log(x1);
//["1", "2"]

x1 = x1.map(Number);
console.log(x1);
//[1,2]


2.将number数组转换为string数组 
 

let x1 = [1,2];
console.log(x1);
//[1, 2]
 
x1 = x1.map(String);
console.log(x1);
//['1','2']


 不私藏,献上开发宝典:http://raboninco.com/1MsLW

猜你喜欢

转载自blog.csdn.net/z00001993/article/details/106092901