every()与some()方法都是JS中数组的迭代方法。
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; }));
运行结果:
some一直在找符合条件的值,一旦找到,则不会继续迭代下去。
every从迭代开始,一旦有一个不符合条件,则不会继续迭代下去。
原文:https://www.cnblogs.com/pwindy/p/12971147.html