I am trying to figure out why console prints undefined
when I use dot notation
when why it prints values of each key when I use bracket notation
.
What I want is to print the values of each key, so I use bracket notation. I just want to know why dot notation doesn't work.
Below is the example.
const sunny = { mac: 'priest', dennis: 'calculating', charlie: 'birdlaw', dee: 'bird', frank: 'warthog' };
for(var key in sunny){
console.log(sunny.key)
}
for(var key in sunny){
console.log(sunny[key])
}
undefined
undefined
undefined
undefined
undefined
"priest"
"calculating"
"birdlaw"
"bird"
"warthog"