js Array of all methods

The following methods will change the value of the object they are called itself:

Array.prototype.copyWithin() 
Within the array, a segment of the sequence of elements copied onto another section of the sequence of elements, the old value.
Array.prototype.fill() 
The values ​​of all elements in the array of the designated section, are replaced with a fixed value.
Array.prototype.pop()
Removes the last element of the array and returns that element.
Array.prototype.push()
Adding one or more elements to the end of the array, and returns the new length of the array.
Array.prototype.reverse()
Reversing the order of elements in the array, i.e. the original becomes a first last, becomes the last original first.
Array.prototype.shift()
Remove the first element of the array and returns that element.
Array.prototype.sort()
Sort of array elements and returns the current array.
Array.prototype.splice()
Add or delete any elements to the array in any position.
Array.prototype.unshift()
Adding one or more elements at the beginning of the array, and returns the new length of the array.

The following method will not change the value of the object they are called, it will return a new array or return an other expectations.

Array.prototype.concat()
It returns a new array and the current array of other combinations of a plurality of arrays or a plurality of values ​​obtained by non-array.
Array.prototype.includes() 
Determine whether the current array contains the values for a specified, if it is returned  true , otherwise  false .
Array.prototype.join()
Connecting a string of all array elements.
Array.prototype.slice()
Extracting some elements of the current in the array are combined into a new array.
Array.prototype.toSource() 
It returns an array of the current literal string representation. Masking on the prototype chain  Object.prototype.toSource()  method.
Array.prototype.toString()
Returns a string combination of all array elements formed. Masking on the prototype chain  Object.prototype.toString()  method.
Array.prototype.toLocaleString()
Returns a string of all array elements by the combination of the localized formed. Masking on the prototype chain  Object.prototype.toLocaleString()  method.
Array.prototype.indexOf()
Returns the index of the first value equal to the specified element of the array, if no such element, or -1.
Array.prototype.lastIndexOf()
Returns an array of the last (first from right number) of the index value equal to a specified element, If no such element, or -1.

Iterative method

In the following a number of traversal methods, there are many ways to specify a callback function as a parameter. Before each array element separately after executing a callback function, length property of the array will be cached somewhere, so if you array is currently in the callback function to add new elements, so those elements are not newly added It will be traversed to. In addition, if the current array of other modifications in the callback function, such as changes in the value of an element or delete an element, then the subsequent traversal operation may be affected by unexpected. In short, do not try to make any changes to the original array traversal, although the specifications for such operations in detail the definition, but for readability and maintainability, please do not do this.

Array.prototype.forEach()
Each element in the array performs a callback function.
Array.prototype.entries() 
Returns an array iterator object, the iterator will contain all the key elements of an array of pairs.
Array.prototype.every()
If each element in the array satisfies the test function returns  true , otherwise it returns  false。
Array.prototype.some()
If there is at least one element in the array to meet the test function returns true, otherwise false.
Array.prototype.filter()
All functions return filter  true  array elements into a new array and returns.
Array.prototype.find() 
Meet the test function finds the first element and returns the value of that element, if found, it is returned  undefined .
Array.prototype.findIndex() 
Meet the test function finds the first element and returns the index of that element, if found, it is returned  -1 .
Array.prototype.keys() 
Returns an array iterator object, which iterator will contain all the key elements in an array.
Array.prototype.map()
It returns a new array of the return value of the callback function of composition.
Array.prototype.reduce()
From left to right for each array element performs a callback function, and the return value of the last callback in a scratchpad passed to the next callback function, and returns the last return value of a callback function.
Array.prototype.reduceRight()
From right to left for each array element performs a callback function, and the return value of the last callback in a scratchpad passed to the next callback function, and returns the last return value of a callback function.
Array.prototype.values() 
It returns an array iterator object, which iterator contains the values ​​of all array elements.
Array.prototype[@@iterator]() 
And above  values() 方法是同一个函数。
Array.prototype.copyWithin() 
Within the array, a segment of the sequence of elements copied onto another section of the sequence of elements, the old value.
Array.prototype.fill() 
The values ​​of all elements in the array of the designated section, are replaced with a fixed value.
Array.prototype.pop()
Removes the last element of the array and returns that element.
Array.prototype.push()
Adding one or more elements to the end of the array, and returns the new length of the array.
Array.prototype.reverse()
Reversing the order of elements in the array, i.e. the original becomes a first last, becomes the last original first.
Array.prototype.shift()
Remove the first element of the array and returns that element.
Array.prototype.sort()
Sort of array elements and returns the current array.
Array.prototype.splice()
Add or delete any elements to the array in any position.
Array.prototype.unshift()
Adding one or more elements at the beginning of the array, and returns the new length of the array.

The following method will not change the value of the object they are called, it will return a new array or return an other expectations.

Array.prototype.concat()
It returns a new array and the current array of other combinations of a plurality of arrays or a plurality of values ​​obtained by non-array.
Array.prototype.includes() 
Determine whether the current array contains the values for a specified, if it is returned  true , otherwise  false .
Array.prototype.join()
Connecting a string of all array elements.
Array.prototype.slice()
Extracting some elements of the current in the array are combined into a new array.
Array.prototype.toSource() 
It returns an array of the current literal string representation. Masking on the prototype chain  Object.prototype.toSource()  method.
Array.prototype.toString()
Returns a string combination of all array elements formed. Masking on the prototype chain  Object.prototype.toString()  method.
Array.prototype.toLocaleString()
Returns a string of all array elements by the combination of the localized formed. Masking on the prototype chain  Object.prototype.toLocaleString()  method.
Array.prototype.indexOf()
Returns the index of the first value equal to the specified element of the array, if no such element, or -1.
Array.prototype.lastIndexOf()
Returns an array of the last (first from right number) of the index value equal to a specified element, If no such element, or -1.

Iterative method

In the following a number of traversal methods, there are many ways to specify a callback function as a parameter. Before each array element separately after executing a callback function, length property of the array will be cached somewhere, so if you array is currently in the callback function to add new elements, so those elements are not newly added It will be traversed to. In addition, if the current array of other modifications in the callback function, such as changes in the value of an element or delete an element, then the subsequent traversal operation may be affected by unexpected. In short, do not try to make any changes to the original array traversal, although the specifications for such operations in detail the definition, but for readability and maintainability, please do not do this.

Array.prototype.forEach()
Each element in the array performs a callback function.
Array.prototype.entries() 
Returns an array iterator object, the iterator will contain all the key elements of an array of pairs.
Array.prototype.every()
If each element in the array satisfies the test function returns  true , otherwise it returns  false。
Array.prototype.some()
If there is at least one element in the array to meet the test function returns true, otherwise false.
Array.prototype.filter()
All functions return filter  true  array elements into a new array and returns.
Array.prototype.find() 
Meet the test function finds the first element and returns the value of that element, if found, it is returned  undefined .
Array.prototype.findIndex() 
Meet the test function finds the first element and returns the index of that element, if found, it is returned  -1 .
Array.prototype.keys() 
Returns an array iterator object, which iterator will contain all the key elements in an array.
Array.prototype.map()
It returns a new array of the return value of the callback function of composition.
Array.prototype.reduce()
From left to right for each array element performs a callback function, and the return value of the last callback in a scratchpad passed to the next callback function, and returns the last return value of a callback function.
Array.prototype.reduceRight()
From right to left for each array element performs a callback function, and the return value of the last callback in a scratchpad passed to the next callback function, and returns the last return value of a callback function.
Array.prototype.values() 
It returns an array iterator object, which iterator contains the values ​​of all array elements.
Array.prototype[@@iterator]() 
And above  values() 方法是同一个函数。

Guess you like

Origin www.cnblogs.com/shixingwen/p/12159880.html