Hey, that is because prop
is not the actual key you are looking for. You are looking for the value the variable prop
holds. So prop
holds a value, instead of being a value itself. Using the dot notation JS will expect an actual value (a string). Using bracket notation JS allows you to use a variable.
Example:
var prop = "album"; // suppose there is a key "album"
In this case object[prop]
is equal to object["album"]
which is again equal to this dot notation: object.album
.
Hope that makes sense.