编辑代码

let arr = [1,2,3,4,5,6]
let obj = {
    name:"124",
    obj1:{name:"456"},
    arr,
    age:function(){
        console.log("age");
        }
    }
function deepClone(obj){
     // 对特殊情况的处理
    if(obj == null) return null;
    if(obj instanceof Date) return new Date(obj);
    if(obj instanceof RegExp) return new RegExp(obj);
    // ....
    if(obj instanceof Array) {
        return new Array(...obj)
    } 
    // 递归的出口
    if(typeof obj !== "object") {return obj;}
  
    let cloneNew = {};
    for (key in obj){
        if(obj.hasOwnProperty(key)){
               cloneNew[key] =  deepClone(obj[key]);
        }
    }
    return cloneNew;
}
let newobj = deepClone(obj);
newobj.name = "nn"
newobj.obj1.name="67";
newobj.arr[0]=0
console.log(obj);
console.log(newobj);