let o = {} let obj = { a: 1, arr: [1, 2], obj: { c: 1 }, func: function () { console.log(123) } } function copyRight(d, r) { for (let key in d) { if (d[key] instanceof Object && !(d[key] instanceof Array) && !(d[key] instanceof Function)) { r[key] = {} copyRight(d[key], r[key]) } else if (d[key] instanceof Array) { r[key] = [] copyRight(d[key], r[key]) } else { r[key] = d[key] } } } copyRight(obj, o) console.log(o )