How to combine js arrays

js array merge

let list = ["zs", "ls", "ww"];
let list2 = [18, 19, 20];
let list3 = ['老', '弱']

Array.concat() merges two arrays and returns a new array without changing the original array

let arr = list.concat(list2, list3)

spread operator […list1, …list2,  …]

let arr = [...list, ...list1, ...list2]

push(...arr), will change the original array

list.push(...list2, ...list3)

for + push

for(let i in list2) {
    
    
   list.push(list2[i])
}

arr1.push.apply(arr1, arr2)

list.push.apply(list, list2)

Guess you like

Origin blog.csdn.net/qq_52099965/article/details/127990673