代码语言:javascript复制
// 三种数组复制方法
// 1. by slice
var arr = [1, 2, 3], copyArr;
copyArr = arr.slice();
// 2. by concat
var arr = [1, 2, 3], copyArr;
copyArr = arr.concat();
// 3. by loop
var arr = [1, 2, 3], copyArr = [];
for (var i = 0; i < arr.length; i) {
copyArr.push(arr[i]);
}
参考:javascript 三种数组复制方法的性能对比