一个数组["125","445","22","45","68","32","98"],想要变成[125,445,22,45,68,32,98],不用for循环,怎么做
走同样的路,发现不同的人生
(function(){ var arr = ["125","445","22","45","68","32","98"]; arr = arr.map(function(el){return parseInt(el);}); });
php//其实也是循环 var arr=["125","445","22","45","68","32","98"].map(function(i){ return +i; }) console.log(arr);
php
//其实也是循环 var arr=["125","445","22","45","68","32","98"].map(function(i){ return +i; }) console.log(arr);
妥善的转换方式显然是 parseInt
parseInt
console.log( + "100rmb" ) // NaN
a.reduce(function(prev, a){ prev.push(+a); return prev;}, []);
//其实还是循环
(function(){
var arr = ["125","445","22","45","68","32","98"];
arr = arr.map(function(el){return parseInt(el);});
});
妥善的转换方式显然是
parseInt
//其实还是循环