合并数组

let a= [1,2,3];
let b = [4,5,6];
a合并b

①push.apply 改变a数组
a.push.apply(a,b)
// 结果a=[1,2,3,4,5,6];相当于a.push(4,5,6)

②concat 不改变a、b数组,返回新数组,浪费内存,可合并多个数组
let c = a.concat(b)

③for循环 改变a数组
for(let i in b){
  a.push(b[1])
}

 

posted @ 2019-08-16 14:16  一个一  阅读(135)  评论(0)    收藏  举报