数组的深浅复制

``````    // 浅复制
var arr = ["one","two","three"];
var arrto = arr;
console.log(arr, arrto); // ["one","two","three"] ["one","two","three"]
arrto[0] = 1;
console.log(arr, arrto); // [1,"two","three"] ["one","two","three"]
``````

``````    // 深复制
var arr = ["one","two","three"];
var arrto = [];
for (var i = 0; i < arr.length; i++) {
arrto[i] = arr[i];
}
console.log(arr, arrto); // ["one","two","three"] ["one","two","three"]
arrto[0] = 1;
console.log(arr, arrto); // ["one","two","three"] [1,"two","three"]
``````

arr数组中的每个元素都是字符串，属于js的基本类型，可以直接传递值，遍历数组arr将数组中的每个元素传给新数组arrto就能实现数组的深复制。

1.slice 可以从已有的数组中返回选定的元素，且返回的是一个新数组

``````    var arr = ["one","two","three"];
var arrto = arr.slice(0);
console.log(arr, arrto); // ["one","two","three"] ["one","two","three"]
arrto[0] = 1;
console.log(arr, arrto); // ["one","two","three"] [1,"two","three"]
``````

2.concat : 连接两个或多个数组,返回新数组

``````    var arr = ["one","two","three"];
var arrto = arr.concat([]);
console.log(arr, arrto); // ["one","two","three"] ["one","two","three"]
arrto[0] = 1;
console.log(arr, arrto); // ["one","two","three"] [1,"two","three"]
``````

3.map ：返回一个由原数组中的每个元素调用一个指定方法后的返回值组成的新数组。

``````    var arr = ["one","two","three"];
var arrto = arr.map(ele=>ele);
console.log(arr, arrto); // ["one","two","three"] ["one","two","three"]
arrto[0] = 1;
console.log(arr, arrto); // ["one","two","three"] [1,"two","three"]
``````