Profile Lookup - accessing property

I solved the Basic Javascript : Profile Lookup for some reasons 1 point is blurry :

Why are we accessing properties in the object differently ?

Is the logic = We know the name of the property, so to access it ====> .firstName ?
Example : if (contacts[i].firstName .......

But when returning we don’t know the name of the property ====> [prop] ?
Example : return contacts[i][prop];

What is the rule behind this ? Why not something like : contacts[i].(prop) ?

Thanks :slight_smile:

This is invalid syntax, can’t be used

Try reading this

2 Likes

Thank you so much !!! Super clear now ! Thanks !!!