Iterative methods:
Every () runs the given function for each item in the array, and returns True if the function returns true for each item. Use this method to determine whether all items in the array meet a condition, similar to the meaning of &&.
var arr = [1,2,3,4,5,6,7,8];
var everyres = arr.every (function (Item,index,array) {
return (ITEM>2);
});
alert (everyres);
Some () runs the given function for each item in the array, and returns True if the function returns true for either item. Use this method to determine whether all the items in the array meet the criteria. Similar to | | The meaning.
var someres = arr.some (function (item,index,array) {
return (ITEM>2);
});
alert (someres);
Filter () Executes a test function on each item in the array and constructs a new one, and returns a true item to be added to the new array. If an item returns false, the item is not included in the new array
var filterres = arr.filter (function (item,index,array) {
return (ITEM>2);
});
alert (filterres);
The map () runs the given function for each item in the array, returning a list of the results of each function call.
var mapres = Arr.map (function (item,index,array) {
return (ITEM*2);
});
alert (mapres);
ForEach () has no return value.
ForEach () {}
Merge method:
Reduce () accepts the incoming function and the initial value (optional) that is the basis for the merge.
The parameter to pass in contains four parameters, the previous value, the current value, the index of the item, and the array object (the first occurrence of the first iteration is the first parameter when it occurs in the second item).
var arr = [1,2,3,4,5];
var sum = arr.reduce (function (Prev,cur,index,array) {
return prev + cur;
});
alert (sum); 15
The Reduceright () and the reduce () methods are essentially the same, except that they are traversed from the back forward.
var sum = arr.reduce (function (prev,cur,index,array) {
return prev + cur;
});
alert (sum); 15
Several iterative methods and merging methods of arrays 1