const obj = { a:1, b:2, c:{ d:3 } } const obj1 = JSON.parse(JSON.stringify(obj)); function deep(obj){ const newobj = {} for(let key in obj){ if(typeof obj[key] === 'object'){ newobj[key] = deep(obj[key]) }else{ newobj[key] = obj[key] } } return newobj } obj.c.d = 5; console.log(obj) console.log(obj1) console.log(deep(obj))