// 对象深拷贝+数组深拷贝几种方式整理
// 对象深拷贝
let obj = { name: "zs", age: 18 }
// 1.
let obj2 = {}
for (key in obj) {
obj2[key] = obj[key]
}
console.log(obj2);
// 2.
let obj3={...obj}
console.log(obj3);
// 3.
let obj4=Object.assign({},obj)
console.log(obj4);
// 4.
let obj5=JSON.parse(JSON.stringify(obj))
console.log(obj5);
// 数组的深拷贝
let arr=[1,2,3,4,5,6]
// 1.
let arr2=[...arr]
console.log(arr2);
// 2.
let arr3=[].concat(arr)
console.log(arr3);
// 3.
let arr4=[]
for(let i=0;i<arr.length;i++){
arr4.push(arr[i])
}
console.log(arr4);