Loading lessons...
Object Properties
Object Properties
Properties are the building blocks of objects. You can add, change, and remove them.
Add a property
const person = { name: "Ada" };
person.country = "England"; // added now
Change a property
person.name = "Ada Lovelace";
Delete a property
delete person.age;
Check if a property exists
"name" in person; // true
person.name !== undefined; // also true
List all property names
Object.keys(person); // ["name", "country"]
Computed property access
Use bracket notation with a variable when you do not know the key name in advance:
let key = "name";
person[key]; // same as person["name"]
TL;DR
- Add and change properties by assignment.
deleteremoves a property.inchecks if a property exists.Object.keys()lists property names.