Js数组的map,filter,reduce,every,some方法

var arr=[1,2,3,4,5,6];

res = arr.map(function(x){return x*x})

[1, 4, 9, 16, 25, 36]

 

res = arr.filter(function(x){return x<3})

[1, 2]

 

res = arr.reduce(function(a,b){return a+b})

21

 

res = arr.every(function(x){return x>7})

false

 

res = arr.some(function(x){return x<3})

true

 

转载于:https://www.cnblogs.com/413xiaol/p/6765651.html

你可能感兴趣的:(Js数组的map,filter,reduce,every,some方法)