1. Array header operations

Graph of TD A [" array operation head "] -- > B [" unshift () "] A [" array operation head "] -- > C/" shift ()"
-unshift () + add one or more values to the front of the array + If you write multiple values to the front of the array, the last value will be written first. And returns the changed array length - shift() + delete the first value of the array + change the original array, return the deleted valueCopy the code

2. Array tail operation

Graph of TD A [array "tail" operation] -- > B [" push () "] A [array "tail" operation] -- > C/" pop ()"
-push () + add one or more values to the end of the array + push changes the array and returns the modified array length -pop () + delete the last value of the array + change the array and return the deleted valueCopy the code

3. The splice:

- Parameter 1: the subscript position at which the deletion began - Parameter 2: the number from the position at which the deletion began, the length of the element to be deleted - Return: array of the values to be deleted Splice method adds values - Parameter 1: the subscript at which the deletion began - Parameter 2: the length of the deletion - All subsequent parameters: the element added at the position at which the deletion beganCopy the code

4. Concat

- Merge array Merges one or more values to the end of an array - You can merge one array into another (expand the array to be merged, only one level) - does not change the original array, but returns a new merged arrayCopy the code

5. Intercept arrays

- splice - Since the deleted array returns the deleted value, it is possible to delete the truncated element, and get the return value - parameter 2 omits the default to the end of the array - It is possible to truncate from a location and specify the length of the truncation - Slice - It is possible to truncate elements in the specified array - parameter 1: Start truncated position - Argument 2: end position, not including end position (default to end if omitted) - The original array does not change, and a new array of truncated values is returnedCopy the code

6. Array in reverse order

Reverse method (); Changed the original arrays, and returns the original array references var arr = [" a ", "b", "1", "a", "c", "f", "e"); var re = arr.reverse();Copy the code

7. The sort order

Sort method: If you call sort without passing any arguments, the elements of the array will be sorted as a string. If you want to sort in any other order, you must pass the comparison function to sort. The comparison function takes two arguments. Array.sort((a,b)=>{return a-b}) sort(a,b)=>{return a-b})Copy the code

8. The join methods:

- Convert an array to a string - You can pass arguments in the join method to replace the comma in the string - do not change the array, return a string - The principle is to convert each element to a string by calling toString (null and undefined to empty string)Copy the code

9. IndexOf and lastIndexOf:

IndexOf: - Checks the position of the element's first occurrence in the array - returns -1 if the current element is not present in the arrayCopy the code

10. The toString () and toLocalString () :

ToString () converts an array to a string, and sometimes toString toLocalString() is called for implicit conversions depending on the environment on which the computer is runningCopy the code

11.forEach

forEach(): - forEach takes a callback function as an argument, and the values of the array are executed in turn. - The callback function takes three arguments - Parameter 1: the element currently in the array of the function - Parameter 2: the index of the element currently in the array of the function - parameter 3: A reference to the current array - a vacancy in the array will not enter forEach - forEach does not return a value - the callback in forEach for this is pointing to the windowCopy the code

12.map

ForEach: - Iterates through the array and returns an array of the same length as the original array. - The original array is executed each time through the callback function. The current callback function returns the value of the corresponding position in the array. - Map returns an array of the same length as the original array. ForEach does not return a valueCopy the code

13. Every and some

The every method - in the same format as forEach - passes each value of the array to the callback function. If one of the callbacks returns false, it stops traversal. Every returns false. The entire every method returns true some: If one of the callbacks returns true, the loop is stopped, and some returns true. If the global loop is complete and all callbacks return false, then some returns falseCopy the code

14.filter

Filter: - Filter - same as forEach - returns an array of values into the callback function. When the callback returns true, the value is added to the new array returnedCopy the code