forEach();
some();
every();
map();
filter();
第一个参数是遍历的数组内容,第二个参数是对应的数组索引,
第三个参数是数组本身
var arr = [1,2,3,4];
var sum = 0;
arr.forEach(function(value,index,array){
array[index] == value; //结果为true
sum+=value;
});
console.log(sum); //结果为 10
"use strict";
var a = [1,2,3,4];
var b = [1,2,3,4,5,6];
console.log(a.every(item_a =>{
return b.some(item_b => {
return item_a===item_b;});
}));
var oldArray = [1,2,3,4,5,6,7,8,9,10];
var newArray = oldArray.filter(val=>{
return val < 6;
});
console.log(newArray);
var oldArray = [1,2,3,4,5];
var newArray = oldArray.map(val=>{
return val+3;
});
console.log(newArray);