Adding & Removing Keys

Modifying object structure.

Examples

Adding Property

Adding a 'lastName' property to the person object.

const person = {firstName:"John"};
person.lastName = "Doe";
console.log(person);

Deleting Property

Removing the 'age' property.

const person = {firstName:"John", age:50};
delete person.age;
console.log(person.age); // undefined

Check Property Existence

Checking if a property exists using 'in'.

const person = {firstName:"John"};
console.log("firstName" in person); // true
console.log("age" in person); // false

Test Your Knowledge

JavaScript Quiz

No quiz available for this topic yet.