javascript / beginner
Snippet
Accessing Object Properties
You can access values in an object using dot notation (object.key) or bracket notation (object['key']). Brackets are required if the key contains spaces or is stored in a variable.
snippet.js
1
2
3
const car = { brand: "Tesla" };console.log(car.brand); // Dot notationconsole.log(car["brand"]); // Bracket notation
nodejs
Breakdown
1
car.brand
The standard way to access properties when you know the name.
2
car["brand"]
Alternative way using a string, useful for dynamic property access.