Bracket notation reads a property whose name is stored in a variable. JavaScript can also turn an object’s keys, values, or entries into arrays so ordinary loops can inspect them.
const stock = { apples: 4, pears: 2 };
const selectedFruit = "pears";
console.log(stock[selectedFruit]); // 2
for (const [fruit, count] of Object.entries(stock)) {
console.log(`${fruit}: ${count}`);
}Along the way, add dynamic properties, test whether a key exists, and choose between Object.keys, Object.values, and Object.entries for different iteration jobs.