ES6数组解构(...array)实现数组复制
vararr1=['a','b','c','d'];
vardd=[...arr1];
dd[]='es6';
console.log(dd);//["es6", "b", "c", "d"]
console.log(arr1);//["a", "b", "c", "d"]
数组concat方法,实现数组复制
vararr1=['a','b','c','d'];
varcc=arr1.concat();
cc[1]='yy';
console.log(arr1);//["a", "b", "c", "d"]
console.log(cc);//["a", "yy", "c", "d"]
通过es6数组解构实现数组合并
var arr1=['a','b','c','d'];
var arr2=['d'];
var arr3=['e','f'];
var dd=[...arr1,...arr2,...arr3];
console.log(dd);//["a", "b", "c", "d", "d", "e", "f"]
通过concat方法实现数组合并
var arr1=['a','b','c','d'];
var arr2=['d'];
var arr3=['e','f'];
var cc=arr1.concat(arr2,arr3);
console.log(cc);//["a", "b", "c", "d", "d", "e", "f"]
领取专属 10元无门槛券
私享最新 技术干货