Dynamic way to acces propeties runtime

Bracket notation is very useful because sometimes object properties are not known before runtime or we need to access them in a more dynamic way

how the Bracket notation look for the value of the array’s property at run time .
even if property is unknown?

SOURCE => https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-data-structures/access-property-names-with-bracket-notation

I don’t understand the question. Can you rephrase it?

It means that before runtime we do not know the property that we will be looking for. For example, in this case:

let selectedFood = getCurrentFood(scannedItem);
let inventory = foods[selectedFood];

selectedFood is a variable which doesn’t gets its value until runtime. Ony when the function getCurrentFood is executed does it gets its value. And then that value will be the name of the property that we are looking for in the object.

1 Like