JS | 数组操作
假设a = [1,2,3] , b=[4,5,6]
现将修改a数组,将b数组的元素扁平化push到a中,a=[1,2,3,4,5,6]
var a = [1,2,3],b=[4,5,6];
[].push.apply(a,b);
console.log(a);
现将修改a数组,将b数组作为a的一个元素push到a中,a=[1,2,3,[4,5,6]]
var a = [1,2,3],b=[4,5,6];
a.push(b);
console.log(a)
现将a,b合并成一个新的数组,但不影响原来的a,b数组
var a = [1,2,3],b=[4,5,6];
console.log(a.concat(b));
console.log(a);
//-------
var a = [1,2,3] ,b = [4,5,6];
console.log([...a,...b]);
console.log(a)