- map 映射
let arr=[1,2,3]
arr.map(item=>item*2)
- reduce 汇总
let arr1 = [1, 0, 4, 0, 10];
arr1 = arr1.reduce((temp, item, index) => {
return temp + item;
});
console.log(arr1);
中间结果
/* 中间结果是temp ,index是下标
第一次temp是1 = arr1[0],item=0,index就是1
第二次temp是1 ,item=4, index就是2
/
/ 当前的零食结果 temp + 加上这一次的 item 就是 中间结果
*/
- filter 过滤器
let arr2 = [1, 4, 15, 16, 10];
arr2 = arr2.filter(item => item % 2 == 0);
console.log(arr2);
let goods = [
{ title: "男士包", price: 10 },
{ title: "女士包", price: 10000 },
{ title: "男士衬衫", price: 100 },
{ title: "女士鞋", price: 20000 }
];
let result = goods.filter(item => item.price >= 10000);
console.log(result);
- forEach 迭代
let arr5 = [1, 23, 4, 56, 9];
arr5.forEach((item, index) => {
console.log(item + " " + index);
});