60 字
1 分钟
数组合并常用方法
①ES6扩展运算...
let arr1 = [1,3,5],
arr2 = [2,4,6]
let newArr = [...arr1,...arr2]
②遍历添加
let arr1 = [1,3,5],
arr2 = [2,4,6]
// forEach、map、filter、every、for、for in、for of等等
arr1.forEach(item => {
arr2.push(item)
})
③concat
方法
let arr1 = [1,3,5],
arr2 = [2,4,6]
arr1.concat(arr2)
④splice
方法
let arr1 = [1,3,5],
arr2 = [2,4,6]
arr1.splice(arr.length, 0, ...arr2)