This article mainly introduces the iterative method of array arrays in JavaScript, and analyses the definition and use techniques of array arrays, and needs friends to refer to the following
The examples in this article describe the JavaScript iteration approach. Share to everyone for your reference. The implementation methods are as follows:
The code is as follows:
Filter () Determines whether an item contained in an array is returned by using the specified function.
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 runs the result of an incoming argument on a 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 () to query whether an item in the array meets a condition every () the arguments that must be passed in each return true, and 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 () Incoming arguments for each entry in the array, no return value
var num = [1,2,3,4,5,4,3,2,1];
Num.foreach (function (item, index, array) {
return item;
})
I hope this article will help you with your JavaScript programming.