var deepCopy = function(source) {
var result = [];
for (var key in source) {
result[key] = typeof source[key]==='object'? deepCopy(source[key]): source[key];
}
return result;
};
深拷贝,逐级拷贝
数组深拷贝
let a1 = [{ age: 1 }];
// loadsh
// json
let a2 = JSON.parse(JSON.stringify(a1))
a2[0].age = 2
console.log(a1, a2)
// a1= [1,3,4,5] ;
a2 = a1.slice(0);
// let a3 = a1.concat()
a3[0] = { age: 2 }
console.log(a1, a3)