0
Why is it showing "undefined"???
let obj = {a: 1, b: 2, c: 3}; for( let key in obj ){ console.log(obj.key); } Why , undefined?
2 Antworten
+ 3
With (for/in) loops you need to us the bracket notation to retrieve the value from the object.
https://code.sololearn.com/WKtS9CO2tvXf/?ref=app
+ 3
let obj = {a: 1, b: 2, c: 3};
for(let val of Object.values(obj)){
console.log(val);
}
(You can do the same with keys.)