function deepObj(obj){ var dest={}; for(var key in obj){ if(typeof obj[key]==='object'){ dest[key]=obj[key].constructor===Array?[]:{}; deepObj(dest[key],obj[key]); }else{ dest[key]=obj[key] } } return dest; } var obj={name:'aa',addr:'werwer',arr:[{name12:'aa',addr12:'werwer'}]} var des=deepObj(obj) des.arr.name12='aaaaa' console.log(des) console.log(obj)
标签:obj,对象,des,js,dest,key,var,拷贝,deepObj From: https://www.cnblogs.com/howhy/p/17834185.html