I am confused about how to reference a nested property inside an object using variables. In the challenge we are given three variables as inputs to the function, however when trying to reference the property I just get undefined when using chained dot and bracket notation… How are we supposed to reference a nested property using variables?
Hey, you can’t use dot notation with variables. You can use: collection[id][prop] to acces a property.
In what sense? One of the main reasons to use bracket notation is to index using a variable, e.g.
foo[bar]. If you meant something more specific, please reflect that in your explanation.
I’m sorry. I confused the two. I meant dot notation. Bracket notation is indeed used for variables. Thanks for noticing, I edited my post.
This thread is old, but in case somebody comes here, like me, having encountered this issue: I found this Medium article about dot notation vs bracket notation really helpful.