1、map速度比foreach快
2、map會返回一個新數組,不對原數組產生影響,foreach不會產生新數組,
3、map因爲返回數組所以可以鏈式操作,foreach不能。
var ary = [12,23,24,42,1];
var res = ary.forEach(function (item,index,input) {
input[index] = item*10;
})
console.log(res);//-->undefined;
console.log(ary);//-->會對原來的數組產生改變;