21 kinds of common methods js array

1 concat() 

  Connecting two or more arrays, and returns the result

  The method returns a new array after execution, has no effect on the original array

  Parameter can have multiple more that can be filled from time to fill all

 

2 every

  Detecting whether each element in the array complex condition

 

  Return value : If the array has a non-compliance return false  all in compliance return true

 

  Parameters two parameters first parameter is a callback function (a function parameter)

3 filter

  The detection elements in the array, return the new array element composed of qualified

  Return valuereturns a new array

 

  Parameters  The first parameter is the callback

4 find()

  Each element in the array are called once, returns the first matching element

  The return value returned is the first matching element

  The first parameter is a callback  has to return the second parameter substitution callback of this directed

5 findindex

  Each element in the array once, returns the index of the first matching array element usage and find () as

6 forEach()

 

  Each element of the array call, and elements are passed to the callback  with the for loop as

 

  Is a process of elements, no return value

 

  Return value  no return value is always undefined

 

  The first parameter is the callback

  The second parameter is used to replace the callback of this directed

 

 

7 map()

  Returns a new array, the array elements are new callback return value after execution

 

  Return value : returns a new array

 

  The first parameter is the callback callback must return a value

  The second parameter is used to replace the callback of this

8  includes()

   Analyzing an array contains a specified value have returns true  not return false

 

  Return value  boolean

 

  Parameter value specified

9 indexof()

 

  Search for a location in the array element with its index is returned, there is no return -1

 

  Return Value digital index and -1

 

  Parameter value specified

10 join()

  All elements of the array will be converted into a string of heavy

 

  Return value returns a new string

 

  Parameters specified delimiters do not write default is a comma

11 push()

 

  To add a new element of the array of items at the end modify the original array

 

  Return value array new length

 

  Parameters element

12 pop()

 

  Delete the last element in the array of the original array to be changed

 

  The return value returned is to remove that element

 

  Parameters no parameters

13 reduce()

 

 

  Current element operation callback function, a return value can not be separated before the element. The second is generally performed from the beginning of the return value

 

  Parameters The first parameter is a callback function must return a value or is undefined

14 reverse () inverted array

  Reverse the order of the array

  The return value is an array of the reversed, changed the original array

  Parameters no parameters

15 unshift()

 

  Add one or more elements to the beginning of an array

 

  The return value  of new added length of the array upon return

 

  Parameters  element to add

16 shift()

 

  Remove the first item in the array

 

  Return value  returns that element is deleted

 

  Parameters  no parameters

17 slice()

 

  Taken from the original array and return part of the element

 

  The return value of a new array of new elements to the array configuration taken

 

  Parameters start position and end position ( does not include the last element ) before and after the opening and closing

18 some()

 

  Are there qualified to retrieve the array elements, as long as there is compliance with a return to true , does not meet the full return false return value is boolean

 

  Parameter is a callback function callback function must return a value

19 sort()

 

  Elements of the array to be sorted by 0-9-az the order

 

  Return Value new array arrangement after

 

  Parameters callback

20 splice()

  An item specified start deleting from an array of elements or add new elements will change the original array

  The return value is an array If you delete the element returns a new array of elements that make up this writing deleted

  If you do not delete returns an empty array

  The first argument must fill the starting position

  The second parameter  to delete the number of elements can beindicates no deletion does not delete the fill behind all

  The third category parameters  from third parameter to start new elements are added back

21 tostring()

 

  Array into a string and returns the string

 

  Return value  string after conversion

 

  Parameters no parameters

 

Guess you like

Origin www.cnblogs.com/lichenfei/p/12403168.html