Record Collection challenge accessing nested object properties

Record Collection challenge accessing nested object properties
0

#1

https://www.freecodecamp.com/challenges/record-collection

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?


#2

Hey, you can’t use dot notation with variables. You can use: collection[id][prop] to acces a property.


#3

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.


#4

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.


#5

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.