利用递归方式遍历所有属性进行深层对象拷贝:
function cloneDeep(object) { if (typeof (object) == 'object') { if (Array.isArray(object)) { var obj = [] } else { var obj = {} } for (key in object) { if (typeof (object[key]) == 'object') { obj[key] = cloneDeep(object[key]) } else { obj[key] = object[key] } } } else { var obj = object } return obj }
标签:object,obj,Javascript,else,key,简单,var,拷贝 From: https://www.cnblogs.com/mesmerize/p/16895960.html