javascript / beginner
Snippet
Object Property Access
Objects store data in key-value pairs. You can access these values using a dot (dot notation) or square brackets (bracket notation).
snippet.js
1
2
3
4
const car = { brand: 'Tesla', model: 'Model 3' };console.log(car.brand); // Dot notationconsole.log(car['model']); // Bracket notation
Breakdown
1
car.brand
Standard way to access the 'brand' property of the car object.
2
car['model']
Alternative way, useful when the property name is stored in a variable.