every()与some()方法都是JS中数组的迭代方法。
every相当于都得符合条件才可返回True,&&
every()
是对数组中每一项进行回调函数内的判断,如果该函数对每一项返回true,则返回true。
some相当于有一个符合条件就可返回True,||
some()
是对数组中每一项进行回调函数内的判断,如果该函数对任一项返回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;
}));
console.log( arr.every( function( item, index, array ){
console.log( 'item=' + item + ',index='+index+',array='+array );
return item > 3;
}));