递归深拷贝
const obj = {
name:'测试',
age:'25',
address:{
name:'杭州'
},
arr:['a','b','c']
}
const obj1=cloneDeep(obj)
function cloneDeep(obj) {
//存放数据
var newobj = obj instanceof Array?[]:{}
//进入循环
for(var k in obj){
if(typeof obj[k] === 'object'){
newobj[k]=cloneDeep(obj[k])
}else{
newobj[k] = obj[k]
}
}
return newobj
}