//一个简单的基于循环的js深拷贝
function copy(obj) {
if (Array.isArray(obj)) {
let arr = [];
for (let i = 0; i < obj.length; i++) {
arr[i] = obj[i];
}
return arr;
} else {
let arr = Object.keys(obj);//获取对象的所有键名,并以数组返回
let obj2={};
for (var i = 0; i < arr.length; i++) {
obj2[arr[i]] = obj[arr[i]];
}
return obj2
}
}