Array.prototype.push
Push is used to add one or more elements to the end of the array and to return the new length, changing the length of the original array, adding the new value to the tail of the array
Array.prototype.pop
Deletes the last element in an array, and returns the element
Array.prototype.concat
The Concat () method is used to combine two or more arrays.
Instead of changing the original array, this method returns a new array.
Array.prototype.constructor
The constructor property returns the constructor of the object
Cases:
JavaScript Array constructor property returns function Array () {[native code]}
JavaScript Number constructor property returns function number () {[native code]}
JavaScript String constructor property returns function String () {[native code]}
Array.prototype.copyWithin
The Copywithin () method is used to copy an element from the specified position in the array to another specified position in the array.
Array.prototype.entries (), keys () and values ()
Three are all new ways to ES6
Used to iterate over an array. They all return a Walker object that can be traversed with a for...of loop
The only difference is that keys () is a traversal of key names
VALUES () is the traversal of a key value
Entries () is a traversal of key-value pairs
Array.prototype.every
The Every () method is used to detect whether all elements of an array conform to a specified condition (provided by a function).
The Every () method detects all elements in the array using the specified function:
- If an element is detected in the array that is not satisfied, the entire expression returns false , and the remaining elements are no longer instrumented.
- Returns true if all elements satisfy the condition.
Array.prototype.fill
The fill () method is used to replace an element of an array with a fixed value.
Array.prototype.map (), filter (), some (), every (), ForEach ()
Map (): Returns a new array with each element as the result of calling Func
Filter (): Returns an array of elements that conform to the Func condition
Some (): Returns a Boolean that determines whether an element meets the Func condition
Every (): Returns a Boolean that determines whether each element conforms to the Func condition
ForEach (): No return value, just call func for each element
Array.prototype.find (), FindIndex ()
The Find () function is used to find the target element, the element is returned, and the return undefined is not found.
The FindIndex () function also finds the target element, finds the location of the returned element, and returns 1 if it is not found.
[1, 2, 3, 4].find (value, index, arr) = = {})
The lookup function has three parameters.
Value: The array element to find for each iteration.
Index: The indexed array element for each iteration of the lookup.
ARR: The array being looked up.
Array.prototype.includes
The includes () method is used to determine whether an array contains a specified value, or False if it returns true.
[1, 2, 3].includes (2); True[1, 2, 3].includes (4); False[1, 2, Nan].includes (NaN); True
Array.prototype.indexOf
The IndexOf () method returns the position of the first occurrence of a specified string value in a string.
[1,2,3,4].indexof (3) //2
Array.prototype.join
The join () method is used to concatenate all the elements in the array into a single string.
element is delimited by the specified delimiter.
[1,2,3].join (' @ ') // [email protected]@3
Array.prototype.lastIndexOf
Searches the entire one-dimensional Array for the specified object and returns the index of the last occurrence.
[2,2,1,1,4,5,3,1,2].lastindexof (1) // 7
Array.prototype.reduce (), Reduceright ()
reduce()
Method receives a function callback
as an accumulator (accumulator), and each value (from left to right) in the array begins to merge, resulting in a value
Array.reduce (callback[, InitialValue])
function Callback (accumulator, CurrentValue, Currentindex, array) {}
accumulator
: The value returned by the last call to the callback, or the provided initial value (InitialValue)
currentValue
: Array items that are currently being processed in the array
currentIndex
: The index value of the current array item in the array
array
: reduce()
An array of call methods
and initialValue
as callback
the first argument to call the function for the first time
var arr = [0,1,2,3,4];arr.reduce (function (accumulator, CurrentValue, Currentindex , array) { return accumulator+//
reduceRight()
The functions and functions of the method are the reduce()
same, but the array items in the array are added reduceRight()
forward from the end of the array.
Array.prototype.reverse
The reverse () method reverses the order of the elements in the array
The method changes the original array without creating a new array
Array.prototype.shift
The Shift () method removes the first element from the array and returns the value of the first element .
If the array is empty, then the shift () method will not take any action, returning the undefined value. Note that the method does not create a new array, but instead modifies the original arrayobject directly.
Array.prototype.slice
The slice () method returns the selected element from an existing array without changing the original array.
Arrayobject.slice (Start,end)
Returns a new array containing elements from start to end (excluding the element) from the Arrayobject.
Array.prototype.sort
sort()
method to sort the elements of the array in situ and return the arrays. Sort ordering may be unstable. The default is sorted by the Unicode code point of the string
Array.prototype.splice
The splice () method adds/deletes an item to/from the array, and then returns the item that was deleted.
The method will change the original array
Arrayobject.splice (index,howmany,item1,....., ItemX)
index: Required. An integer that specifies the location of the Add/remove item, using a negative number to specify the position from the end of the array.
howmany: Required. The number of items to delete. If set to 0, the item is not deleted.
Item1, ..., ItemX: Optional. Adds a new item to the array.
The splice () method deletes 0 or more elements starting at index and replaces the deleted elements with one or more values declared in the argument list.
If the element is removed from the Arrayobject, the array containing the deleted element is returned.
Array.prototype.toLocaleString
Converts an array to a local string.
The toLocaleString () method of each array element is called first, and then the resulting string is concatenated using a locale-specific delimiter to form a string
["Red", "Black", "green"].tolocalestring () // red,black,green
Array.prototype.toString
You can convert an array to a string and return the result (without changing the original array)
Array.prototype.unshift
The Unshift () method adds one or more elements to the beginning of the array and returns the new length.
Note: This method will change the number of arrays.
tip: You can use the push () method to add a new item to the end of the array.
Array of all prototypes, array methods