Properties
Properties
Section titled “Properties”Introduction
Section titled “Introduction”Object properties are the key-value pairs stored in an object. Keys are strings (or Symbols), and values can be any type.
Accessing Properties
Section titled “Accessing Properties”const user = { name: 'Alice', age: 25 };
// Dot notationuser.name; // 'Alice'
// Bracket notation (for dynamic keys)user['name']; // 'Alice'const key = 'age';user[key]; // 25Adding and Updating
Section titled “Adding and Updating”const user = { name: 'Alice' };user.age = 25; // Add new propertyuser.name = 'Bob'; // Update existinguser['isActive'] = true; // Bracket notationDeleting Properties
Section titled “Deleting Properties”const user = { name: 'Alice', age: 25 };delete user.age;console.log(user.age); // undefinedProperty Enumeration
Section titled “Property Enumeration”const user = { name: 'Alice', age: 25 };
Object.keys(user); // ['name', 'age']Object.values(user); // ['Alice', 25]Object.entries(user); // [['name', 'Alice'], ['age', 25]]Summary
Section titled “Summary”- Access with
.(static) or[](dynamic) - Add/update by assignment
- Delete with
deleteoperator - Use
Object.keys/values/entriesfor enumeration