The 1.some method sequentially detects whether each element in the array conforms to the condition of a given function, returns a Boolean value, does not process an empty array, and does not alter the original array. In execution, there is a satisfaction that returns true and no longer continues execution
var aa = [1,32,4,26];var bb = aa.some(function(item){ return item > 30;})console.log(bb); // 输出为true
Attention issues
The some callback function has three parameters, one is the current element (must), one is the index of the current element (optional), and one is the array object that the current element belongs to.
The 2.every method sequentially detects whether each element in the array conforms to the condition of a given function, returns a Boolean value, does not process an empty array, and does not alter the original array. All elements are satisfied before returning true
var aa = [3,32,4,26];var bb = aa.every(function(item){ return item > 2;})console.log(bb); // 输出为true
Attention issues
The every callback function has three parameters, one is the current element (must), one is the index of the current element (optional), and one is the array object that the current element belongs to.
The 3.reduce method returns the final value for each element in the array, in turn, by the method of the callback function.
var aa = [3,2,4,1];var bb = aa.reduce(function(total,item){ return total+item;})console.log(bb); // 输出为10
Attention issues
The reduce callback function has four parameters, the first is the sum (must), the value returned, the second is the current element (must), and the third is the index of the current element (optional), and one is the array object to which the current element belongs.
Array of methods Some,every, reduce simple method