General JS Question Regarding Syntax


#1

I have seen this used several times but do not know the official name or when it is ok to use it.

orion["accounts"]

The question is regarding how you can take an object and use the brackets to get it’s properties. What is this called and when can and should it be used?


#2

The name is bracket notation.

You are accessing the accounts property of the orion object.

You may use either:

foo["bar"]

or

foo.bar

to access the bar property of foo.

If foo has no bar property, it will return undefined.

Here is a Stack Overflow answer regarding bracket notation vs. dot notation.

Essentially, bracket notation allows you to use special characters when accessing an object’s property.


#3

Thank you,

I know this was a very rudimentary question but , I had never really used
bracket notation until this point.

Thank you again.