+ 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 ?
1 Réponse
+ 1
use
clonedObj[p]
instead of
clonedObj.p