js字符型数组转成数字型数组

 方式一:

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

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

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

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

 方式二:


var checkStr="1,2,3,4,5";//原始字符串 
var dataIntArr = [];//保存转换后的整型字符串
var dataStrArr = checkStr.split(",");  //分割成字符串数组
dataIntArr = dataStrArr.map(function (i) {
    return Number(i)
});

你可能感兴趣的:(js,javascript,前端,html)