1.forEach用法
var arr=[13,2,2,5]
var sum=0
// forEach用法:Array.forEach(function(数组当前项的值,数组当前项的索引值,数组本身){})
arr.forEach(function(value,index,Array){
console.log("第"+index+"个数组的值是"+value)
console.log("数组本身"+Array)
sum+=value
console.log('sum:'+sum)
})
2.filter用法
// 2.filter用法
// filter用法:Array.filter(function(数组当前项的值,数组当前项的索引值,数组本身){})
var arr2=[33,52,12,22,55] var newArr2=arr2.filter(function(value,index,Array){ return value>20 }) console.log("newArr2:"+newArr2)
标签:遍历,console,迭代,value,filter,forEach,数组,Array From: https://www.cnblogs.com/hs20011205/p/17015030.html