In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the "sorting and iterative method of JavaScript array". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the sorting and iterative method of JavaScript array".
Catalogue
Common methods of array
Array element addition and deletion
Operand header
Operand tail
Add and delete at any location
Array splicing
Convert an array to a string
Intercept array
Array sorting method
Sort
Sequential flip
Array iterative method
Array traversal lookup
The return value is subscript
The return value is content
Array traversal processing
Callback (value [, index [, array]])
Callback (total,value [, index [, array]])
Array other methods
First of all, the significance of the summary is to make the disorder more orderly, so that the process of use will be clearer.
Note how to use the array:
Mutation method and non-variation method. That is, the use of the mutation method will change the original array, while the latter will not. It is marked on the brain map below.
You may need to note that array methods and string methods are similar in several ways. How do arrays and strings switch?
Some method parameters support negative numbers, and some methods have a second parameter that does not represent the number of coordinates.
We can even comb through the callback functions. Most callback functions have the same parameter format, while some callback functions are different.
When split,slice,splice,join,contains,includes,push,pop,shift,unshift or even you are so confused by similar words that you can't tell which is an array method, which is a string method, and which function is what? Of course, I can now tell you whether the above methods are array methods or string methods, or even string methods and arrays, but it's not necessary, because it's hard to remember after all. So let's make a systematic classification and summary, and you can easily distinguish it.
Then you just need to forget your disorganized memories and rebuild your memories by combing them.
Array common methods array elements add and delete Operand headers
Unshift (value) mutation method inserts an element into the head of the array
The shift () mutation method removes the first element of the array header
Operand tail
Push (value) mutation method inserts an element into the tail of an array
Pop () mutation method pops up an element at the end of the array
Add and delete at any location
Splice (start,length [… , value]) mutation method
The second parameter is the number. If it is not 0, it means that you need to delete length elements from start. You can add or delete elements together.
Array splicing
Concat (… Arr) string has this similar method
Convert an array to a string
Join (str) converts an array to a string with a specified character concatenation
ToString () splits the array into strings with the sign ","
Intercept array
Slice (start [, end]) supports negative strings with this similar method
Array sorting method
Sort (callback) mutation method to sort the array
The callback function returns aMub to sort from big to small, and bmura to sort from smallest to largest.
/ / callback callback function format function callback (amemb) {return aMeib} sequence flipped
Reverse () mutation method reverses the order of arrays
Array iteration method array traversal lookup return value is subscript
IndexOf (targetValue) traverses the array from left to right to find the subscript of the target value and returns the first subscript value.
LastIndexOf (targetValue) iterates through the array from right to left to find the subscript of the target value and returns the first subscript value.
FindIndex (callback) judges the condition of the array element through the callback function, and returns the subscript value of the element that meets the condition for the first time.
The return value is content
Find (callback) determines the condition of the array elements through the callback function, and returns the element value that meets the condition for the first time.
Array traversal processing callback (value [, index [, array]]) / / callback callback function format function callback (value, index, array) {/ / processing. Return. / / whether it does not need to be annotated under the retrun statement here.
ForEach (callback) traverses the array only with no return value. Callback does not require return statements
Map (callback) traverses each element of the array using callback to process the array, and adds the callback-processed return value to the new array and returns the new array.
Filter (callback) filters the array and returns a new array of elements whose value is true returned by callback.
Every (callback) traverses the array. If the return value of callback is true, the return value of the method is true.
Some (callback) traverses the array. If one of the callback return values is true, the return value of the method is true
Callback (total,value [, index [, array]]) / / callback callback function format function callback (total,value, index, array) {return total + value;}
Reduce (callback [, initial value])
The array is shortened from left to right, and the result of the previous processing total is passed into the next callback function as an argument for the callback function to use.
ReduceRight (callback [, initial value])
The array is shortened in turn from right to left, while the result of the previous processing total is passed into the next callback function as an argument for the callback function to use.
Array other methods
Includes (value) ES6 determines whether the array contains an element
Thank you for your reading, the above is the content of "sorting and iterative method of JavaScript array". After the study of this article, I believe you have a deeper understanding of the sorting and iterative method of JavaScript array, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.