Check the code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Check the code

const obj1 = { foo: 'bar', x: 42 }; const clonedObj = { ...obj1 }; // { foo: "bar", x: 42 } for(var p in clonedObj ){ console.log(p); console.log(clonedObj.p); } // output foo undefined bar undefined // why the undefined ?

8th Mar 2019, 6:56 PM
Mariem Ben Hassine
Mariem Ben Hassine - avatar
1 Answer
+ 1
use clonedObj[p] instead of clonedObj.p
10th Mar 2019, 5:08 AM
Георгий Вавилов
Георгий Вавилов - avatar