var deepClone = function(obj){
var objClone = Array.isArray(obj)?[]:{};
if(obj&&typeof(obj) === "object"){
for(key in obj){
if(obj.hasOwnProperty(key)){
if(obj[key]&&typeof(obj[key]) === "object"){
objClone[key] = deepClone(obj[key]);
}else{
objClone[key] = obj[key];
}
}
}
}
return objClone;
}
let a=[1,2,3,4];
b=deepClone(a);
console.log(a,b);
07-05
1809
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-03
507
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-29