. 1, some ():
some () method for detecting elements in the array satisfies the specified conditions.
- If there is an element in the array satisfies the condition, the expression returns true, the remaining elements will not perform detection.
- If the array does not meet the conditions of the elements, false is returned.
var arr = [4, 5, 6, 7, 8, 9];
console.log( arr.some( function( item, index, array ){
console.log( 'item=' + item + ',index='+index+',array='+array );
return item > 6;
}));
result:
Note: some true if they are no longer carried out, will not be an empty array detection, does not change the original array
2、every():
every () is run on each item in the array to a given function, the function returns true if for each, it returns true.
- If the array has a detected element is not satisfied, then the whole expression evaluates to false, and the remaining elements will not be detected.
- If all elements conditions are met, it returns true.
var arr = [4, 5, 6, 7, 8, 9];
console.log( arr.every( function( item, index, array ){
console.log( 'item=' + item + ',index='+index+',array='+array );
return item > 6;
}));
result:
Note: every encounter false if it is no longer carried out, will not be an empty array detection, does not change the original array