const obj = { name: 'xiaoming', age: 18, hobby: ['吃饭', '睡觉'], abc: 12, family: { mom: 'xx', daa: 'xxx' }, arr: [1, 2, 3, 4], date: new Date() } function deepClone(sourceObj) { let targetObj if (typeof sourceObj === 'object') { if (Array.isArray(sourceObj)) { targetObj = [] for (const i in sourceObj) { targetObj.push(deepClone(sourceObj[i])) } } else if (sourceObj === null) { targetObj = sourceObj } else if (sourceObj.constructor === RegExp) { targetObj = sourceObj } else if (Object.prototype.toString.call(obj).slice(8, -1) == 'Date') { //时间类型 sourceObj = new Date() sourceObj.setTime(obj.getTime()) } else { targetObj = {} for (const i in sourceObj) { targetObj[i] = deepClone(sourceObj[i]) } } } else { targetObj = sourceObj } return targetObj } console.log(obj) console.log(deepClone(obj))