### some()方法
let arr =[1,2,3,4,5]let a = arr.some((item)=>{return item >3})
console.log('a:', a);// true
console.log('arr: ', arr);// [1,2,3,4,5]> some不会改变原数组
### every()方法
let arr =[1,2,3,4,5]let a = arr.every((item)=>{return item >3})
console.log('a:', a);// false
console.log('arr: ', arr);// [1,2,3,4,5]> every不会改变原数组
### filter()方法
let arr =[1,2,3,4,5]let a = arr.filter((item)=>{return item >3})
console.log('a:', a);// [4,5]
console.log('arr: ', arr);// [1,2,3,4,5]> filter不会改变原数组
### map()方法
let arr =[1,2,3,4,5]let a = arr.map((item)=>{return item *3})
console.log('a:', a);// [3,6,9,12,15]
console.log('arr: ', arr);// [1,2,3,4,5]> map不会改变原数组
### reduce()方法
#### 一元数组求和
let arr =[1,2,3,4,5]let a = arr.reduce((pre,cur,index,array)=>{return pre + cur
})
console.log('a:', a);// 15
console.log('arr: ', arr);// [1,2,3,4,5]
#### 对象数组求和
let arr1 =[{num:1},{num:2},{num:3}]let a = arr.reduce((pre,cur,index,array)=>{return pre + cur.num
},0)
console.log('a:', a);// 6
#### 求最大值,最小值
let arr1 =[1,3,5,6,4,8]let max = arr.reduce((pre,cur,index,array)=> pre > cur?pre:cur)let min = arr.reduce((pre,cur,index,array)=> pre < cur?pre:cur)
console.log('max:', max);// 8
console.log('min:', min);// 1
#### 计算数组中每个元素出现的次数
let arr =[1,2,1,5,1,2,3,6,4,1,2,5,3,3]let a = arr.reduce((pre,cur,index,array)=>{if(cur in pre){
pre[cur]++}else{
pre[cur]=1}return pre
},{})
#### 数组去重
let arr =[1,2,1,5,1,2,3,6,4,1,2,5,3,3]let a = arr.reduce((pre,cur,index,array)=>{if(!pre.includes(cur)){
pre.push(cur)}return pre
},[])
#### 对象数组去重
let arr =[{num:1},{num:1},{num:3}]let obj ={}let a = arr.reduce((pre,cur,index,array)=>{
obj[cur.num]?"":(obj[cur.num]=true&& pre.push(cur))return pre
},[])> reduce不会改变原数组