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

 

posted @ 2017-04-26 00:04  413Xiaol  阅读(200)  评论(0编辑  收藏  举报