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

1、数字数组转化为字符串数组

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
arr.map(String);  //结果: ['1', '2', '3', '4', '5', '6', '7', '8', '9']

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 @ 2021-04-22 11:08  ZerlinM  阅读(832)  评论(0编辑  收藏  举报