js - the use of arrays

1. Array

A collection of one or more values ​​of the same data type.

arr.length array length

2. Create an array

1. Use literals to create an array

2. Use the method of constructor Array to create an array 


 three,

1. push can add a string at the last position

After the push method is executed, it will return the length of an array


2. reverse reverse order 


3、 join     

Use the join method to separate by commas by default

 Parameters can be added in the join( ) method, and what parameters are used as the separator

Split with ' 'null character, which means there is no separator in the middle


4. sort array sorting                                                                     

  Sorting the array will change the original array (this method is suitable for single-digit sorting)       

(2) Multi-digit sorting (using functions)

Sort ab from smallest to largest, sort ba from largest to smallest


5、concat

Merge two arrays and generate a new array 


6. pop deletes the last item in the array 


7. unshift adds an item to the front of the original array

 unshift will return the length of the new array


8. Shift deletes the first item in the array 


9、indexOf

     indexOf returns the index of the character in the array

     ★ If the character does not exist in the array, it will return -1


10. splice adds or deletes the specified position

      splice has three parameters

      The first parameter indicates the position of the array

      The second parameter indicates how many to delete 

      The third parameter indicates adding several 


11. Add splice at the specified position

Guess you like

Origin blog.csdn.net/weixin_68485297/article/details/124390336