Skip to content Skip to sidebar Skip to footer

Need Help With Dot Notation

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

Solution 1:

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.

Post a Comment for "Need Help With Dot Notation"