javascript - 如何用map把数组里的string变成number
怪我咯
怪我咯 2017-04-10 15:29:12
0
4
381

一个数组["125","445","22","45","68","32","98"],想要变成[125,445,22,45,68,32,98],不用for循环,怎么做

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(4)
左手右手慢动作

(function(){
var arr = ["125","445","22","45","68","32","98"];
arr = arr.map(function(el){return parseInt(el);});
});

Ty80
php//其实也是循环
var arr=["125","445","22","45","68","32","98"].map(function(i){
 return +i;
})
console.log(arr);
刘奇

妥善的转换方式显然是 parseInt

console.log( + "100rmb" ) // NaN
大家讲道理
a.reduce(function(prev, a){ prev.push(+a); return prev;}, []);

//其实还是循环

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template