every()與some()方法都是JS中數(shù)組的迭代方法。
every()是對數(shù)組中每一項運行給定函數(shù),如果該函數(shù)對每一項返回true,則返回true。
some()是對數(shù)組中每一項運行給定函數(shù),如果該函數(shù)對任一項返回true,則返回true。
var arr = [ 1, 2, 3, 4, 5, 6 ]; console.log( arr.some( function( item, index, array ){ console.log( 'item=' + item + ',index='+index+',array='+array ); return item > 3; })); //結(jié)果: true console.log( arr.every( function( item, index, array ){ console.log( 'item=' + item + ',index='+index+',array='+array ); return item > 3; })); //結(jié)果: false