Reputation: 11404
Here's an example of my object:
var fruit = {
apple: {
}
}
var apple = this.rel;
Will someone please tell me why this works:
fruit[apple]
and this doesn't?
fruit.apple
Upvotes: 1
Views: 116
Reputation: 523264
In Javascript foo.bar
is equivalent to foo["bar"]
, not foo[bar]
.
Therefore, fruit.type
will become fruit["type"]
, but there isn't a type:
field in the fruit
object, so fruit.type
returns undefined.
Upvotes: 5