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 }
标签:const,name,递归,newobj,obj,var,cloneDeep,拷贝 From: https://www.cnblogs.com/swmin/p/16915374.html