function clone obj let newObj for let key in obj console log Enter Loo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function clone (obj) {
let newObj = {};
for (let key in obj) {
console.log('Enter Loop')
console.log(obj[key]);
if (typeof(obj[key]) == 'object') {
console.log('if pass');
clone(obj[key]);
}
newObj[key] = obj[key];
};
console.table(newObj);
return newObj;
}
let obj = {test: { test2: { test3: '1' } }};
let objCopy = clone(obj);
console.log('Test');
console.log(obj !== objCopy);
console.log(obj.test.test2 !== objCopy.test.test2);
console.log(obj.test.test2.test3 === objCopy.test.test2.test3);