js快速将字符串数组转化为数字数组(互换)

1
1、数字数组转化为字符串数组
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
arr.map(String);  //结果: ['1', '2', '3', '4', '5', '6', '7', '8', '9']
1
2、字符串数组转化为数字数组

 

var a = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
a.map(Number);  //结果:[1, 2, 3, 4, 5, 6, 7, 8, 9]
posted @ 2022-03-07 16:12  土小狗  阅读(122)  评论(0编辑  收藏  举报