Why doesn't dot notation work with this loop? I wrote the following, but I got an error:


#1



Replace this line with your code.

Continuing the discussion from 27 Looks for-in to me:


#3

i find this strange, but objects are also associative arrays in js, i find this weird, someone does a good job at trying to explain it (link)


#5

Because property is a string.

And in dot notation we can't do something like this:

nameOfObject."nameOfProperty"

it must be:

nameOfObject.nameOfProperty // this is not a string

or:

nameOfObject["nameOfProperty"]

#7

you got to be kidding me right? Question of mellauyellow:

The dot notation only with the object name, in your for loop property is a string, which it is why the dot notation is not working, @factoradic just explained this, and it perfectly answers your question!!