Because that’s the syntax that the creators of Javascript decided on or one of the ways.
There are two primary ways to access an object. Bracket notation an dot notation. Brackets have fewer limitations than dot does because you can just use strings and pass variable values.
Thank you for you reply and time.
I forgot that when we want access objects with brackets we have to use quotations as well [" "]. It does make sense to me now .
Not necessarily, only use the quotes when you are accessing the exact name of the key (eg. [“alpha”]). A huge advantage of the brackets is being able to utilize a variable, which would not have the quotes (eg. [val]).
Sorry if that’s confusing at all, but the article Tirjasdyn shared gives a much better example and explains it in-depth.