The first two sections say the basics of creating arrays, queue methods, sorting, and some operation methods, and this section is about iterative and merging methods.
Every () method & Some () method
These two methods run the given function for each item in the array, and then return a Boolean value that can be understood as the difference between everyone and someone, and look at an example:
vararr=[1,2,3,4,5];vareveryresult=arr.every (function (Item,index,arr) {return(item>2); }) //falsevarsomeresult=arr.some (function (Item,index,arr) {return(item>2); }) //true
All two methods execute a function, the first parameter of the function represents each array element of the iteration, the second parameter represents the subscript, and the third parameter represents the array.
Filter () method
1 var arr=[1,2,3,4,5]2var filterresult=arr.filter (function(item, Index,arr) {3 return (item>2)4 }) //[ 3,4,5]
The method executes the given function for each item in the array, and returns a set of items that the function returns True.
Map () Method & ForEach () method
Map () returns an array of the results of each function call, and ForEach () does not return a value.
1 vararr=[1,2,3,4,5]2 varMapresult=arr.map (function(Item,index,arr) {3 returnItem*24})//[2,4,6,8,10]5 varForresult=arr.foreach (function(Item,index,arr) {6 //perform some actions7})//undefined
ForEach () is essentially the same as using a for loop to iterate over an algebraic group.
Reduce () method & Reduceright () method
1 var arr=[1,2,3]; 2 arr.reduce (function(x,y,index,arr) {34 return x+ Y5 },0); // 6
Both methods have two parameters, the first is a callback function to execute, and the second represents the initial value to be used as the basis for the merge (optional).
IndexOf () Method & LastIndexOf ()
1 var arr=[1,2,3,4,5]; 2 arr.indexof (1,-1); // -1 3 arr.lastindexof (1,-1) //0
Receives two parameters, the first represents the element to find, the second represents the start position, and if any, returns the position of the element in the array subscript, No 1
The array is probably summed up so much, at the same time the array is also the object, will later in the object's learning summary to explore.
JavaScript arrays about 3