How to use variables in dot notation like square bracket notation

You can’t use variables in dot notation (short of using eval, which you don’t want to do). With dot notation the property name is essentially a constant.

myObj.propName
// is equivalent to
myObj["propName"]

Leave a Comment