JS Access Object Properties
Syntax
Object properties in JavaScript can be accessed using dot notation or bracket notation.
let value = objectName.key; // Dot notationlet value = objectName["key"]; // Bracket notationExample
let person = { name: "Alice", age: 30, job: "Engineer"};
console.log(person.name); // Outputs: Alice (dot notation)console.log(person["age"]); // Outputs: 30 (bracket notation)
let key = "job";console.log(person[key]); // Outputs: Engineer (using a variable with bracket notation)