1.foreach

usage

  const list =res.data.acct_cate
          const list1=[]
          list.foreach((item,index)=>{
           list1.push(item.name)
       })
Copy the code

Used to iterate over groups of numbers

2. The map method

Blog.csdn.net/liminwang03…

usage

  const list =res.data.acct_cate
          const list1=[]
          list.map((item,index)=>{
           list1.push(item.name)
       })
Copy the code

3. Slice (Strings and arrays)

Do string or array splits

It’s not going to change

Returns a new string or array

Slice (2,4) // let arr = [1,2,3,4,5] // slice(2,4) // let arr = [1,2,3,4,5] [3, 4, 5] let arr2 = arr.slice(2,5)Copy the code

Substr and substring

substr

Substr. substr(start,num) // Selects num characters from the start subscript.Copy the code

substring

Str.substring (start,end) // Intercepts a string, starting with the start subscript and remaining until the end of the end subscript, or until the end of the last character if there is no end, as in the slice method.Copy the code

4. Splice operates on arrays

arr.splice(start,num,arg1,arg2...)
Copy the code

www.jianshu.com/p/9eadb1647…

Is a strong array manipulation method, you can add, delete, change

Note: We operate on the original array

A, delete array elements

Let arr = [1,2,3,4,5,6,7,8,9]; let arr = [1,2,3,4,5, 7,8,9]; [1, 2, 3, 6, 7, 8, 9] Arr. Splice (3,2)Copy the code

Insert arg1, arg2, arg3…

If only start is entered with no other parameters, all subsequent elements are deleted

B, delete and insert elements

Let arr = [1,2,3,4,5,6,7,8,9] Arr. Splice (3,2,1,2, 8, 9); return array [4, 5];Copy the code

C, insert an array

Let arr = [1,2,3,4,5,6,7,8,9] // Add elements 1,2,3 and so on from the index 3. Arr. Splice (3,0,1,2, 8, 9) arr. Splice (3,0,1,2, 9)Copy the code

5. Split string

Splits the string with the specified separator and places it in an array

6. Add and delete methods

Both pairs will change the original array.

Push () // Add one or more elements to the end of the array to return the new array lengthCopy the code
Pop () // Removes the last item of the array, returning the removed itemCopy the code
Shift () // Removes the first item of the array, returning the removed itemCopy the code
Unshift () // Returns the length of the array by adding one or more elements to the front of the first itemCopy the code