- every()對數(shù)組中的每一項(xiàng)都運(yùn)行給定函數(shù)船逮,返回值:當(dāng)且僅當(dāng)全部true時,才會返回true
- filter()對數(shù)組中的每一項(xiàng)都運(yùn)行給定函數(shù)惶傻,返回true項(xiàng)組成的數(shù)組
- forEach()對數(shù)組中的每一項(xiàng)都運(yùn)行給定函數(shù),該方法沒有返回值
- map()對數(shù)組中的每一項(xiàng)都運(yùn)行給定函數(shù),返回新項(xiàng)組成的新數(shù)組
- some()對數(shù)組中的每一項(xiàng)都運(yùn)行給定函數(shù),如果有一項(xiàng)返回true,則返回true
eg:
every
var num=[1,2,3,4,5,4,3,2,1]
var result=num.every(function(item,index,array){
return (item>2)
})
alert( result) //false
-------------------------------
es6
var num=[1,2,3,4,5,4,3,2,1]
var result=num.every(i=>i>2)
alert (result )//false
some
var num=[1,2,3,4,5,4,3,2,1]
var result=num.some(i=>i>2)
alert (result )//true
map
var num=[1,2,3,4,5,4,3,2,1]
var result=num.map(i=>i*2)
alert (result )//[2,4,6,8,10,8,6,4,2]
forEach
var num=[1,2,3,4,5,4,3,2,1]
var result=num.forEach(i=>console.log(i))