capypad
0 day streak
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
javascript
1
2
3
4
const car = { brand: 'Tesla', model: 'Model 3' };
 
console.log(car.brand); // Dot notation
console.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.