every()与some()方法都是JS(ES6)中数组的迭代方法。
原理:every()是对数组中每一项运行给定函数,如果该函数对每一项返回true,则返回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; }));原文:https://www.cnblogs.com/smokefish/p/14769500.html