1.JSON转换
var targetObj = JSON.parse(JSON.stringify(copyObj))
let arr4 = JSON.parse(JSON.stringify(arr))
2.普通递归函数
function deepClone(source){ // 深拷贝
if(!isObject(source)) return source
let target = Array.isArray(source)?[]:{}
for(var k in source){
if(source.hasOwnProperty(k)){
if(typeof source[k] === 'object'){
target[k] = deepClone(source[k])
}else{
target[k] = source[k]
}
}
}
return target
}
function isObject(source){
return (typeof source === 'object' && source !== null)
}