Quickly convert an array in JS to Number type or String type

1. Convert string array to number array 
 

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

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


2. Convert the number array to a string array 
 

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


 Don't hide it privately, present the development book: http://raboninco.com/1MsLW

Guess you like

Origin blog.csdn.net/z00001993/article/details/106092901