Methods for JavaScript iterations
Filter () uses the specified function to determine whether to return an item contained in an array
var num = [1,2,3,4,5,6,12];
Num.filter (function (item, index, array) {
Return (item > 2); [3, 4, 5, 6, 12]
});
Map () returns an array in which each item is the result of running an incoming parameter on the corresponding item in the original array
var num = [1,2,3,4,5,4,3,2,1];
Num.map (function (item, index, array) {
Return (item * 2); [2, 4, 6, 8, 10, 8, 6, 4, 2]
});
Every () some (), query whether an item in the array conforms to a condition every () must pass in the argument each return true, the result is the True;some () method
As long as one is true, the result is true
var num = [1,2,3,4,5,4,3,2,1];
Num.every (function (item, index, array) {
Return (item > 2); False
});
Num.some (function (item, index, array) {
Return (item > 2); True
})
ForEach () Each entry parameter of the array, no return value
var num = [1,2,3,4,5,4,3,2,1];
Num.foreach (function (item, index, array) {
return item;
})
An iterative approach to JavaScript array arrays