How to delete properties from an object

Learn how to delete properties from a JavaScript object.

Deleting properties from an object

delete The operator can be used to delete properties from an object:

Instance

var person = {
  firstName: "John",
  lastName: "Doe",
  age: 50,
  eyeColor: "blue"
};
delete person.age;  // or delete person["age"];
// Before deletion: person.age = 50, after deletion, person.age = undefined

Try it yourself

delete The operator will remove both the value of the property and the property itself.

The property cannot be used before it is re-added.

delete The operator is intended to be used for object properties. It has no effect on variables or functions.

Note:delete The operator should not be applied to predefined JavaScript object properties. It may cause your application to crash.

Related pages

Tutorial:JavaScript object