map----映射--适合转换
reduce---汇总--一个
filter---过滤--适合筛选
forEach---迭代(循环)
/*
map---映射---一个对一个
reduce---汇总---一堆出来一个(适合算总数和平均分)
filter---过滤器
forEach---循环(迭代)
*/
let arr5 = [1,2,3];
// let res = arr5.map(function(item){
// return item * 2;
// })
let res = arr5.map(item=>item*2);
let score = [12,2,38,88,99,44];
let results = score.map(item=>item>=60?'不及格':'及格');
console.log(results);
//reduce----算总和
/*let arr6 = [12,34,55,77,11];
let res6 = arr6.reduce(function(tmp,item,index){//tmp前两个相加的结果,item数值,index索引
return tmp + item;
})
console.log(res6);*/
//reduce---算平均数
let arr7 = [12,34,55,77,11];
let res7 = arr7.reduce(function(tmp,item,index){
if(index != arr7.length -1){//不是最后一次
return tmp + item;
}else{
return (tmp+item)/arr7.length;
}
})
console.log(res7)
//filter---过滤
var arr8 = [12,345,56,678,9,19];
/*var res8 = arr8.filter(function(item){
if(item%3 == 0){//能被3整除的留下
return true;
}else{
return false;
}
})*/
var res8 = arr8.filter(item=>item%3 == 0)
console.log(res8);
let arr9 = [
{title:'男鞋',price:45},
{title:'女鞋',price:324345},
{title:'男报',price:445},
{title:'女包',price:2345},
]
let res9 = arr9.filter(json=>json.price>=1000);
console.log(res9);
//forEach
let arr10 = [12,34,56,7];
let res10 = arr10.forEach((item,index)=>{
console.log(index+':'+item)
});