delete

delete — Remove a property from an object.

Description

delete mixed variable

Parameters

Name Description Type Default Optional
variable The property to remove. mixed No

Return values

boolean.

Examples

Example #1 – delete example
var person = { firstName: "John", lastName: "Doe", email: "john.doe@example.com", }; console.log(person); // {firstName: "John", lastName: "Doe", email: "john.doe@example.com"} console.log(delete person.email); // true console.log(person); // {firstName: "John", lastName: "Doe"}
Example #2 – delete non existant property
var person = { firstName: "John", lastName: "Doe", }; console.log(delete person.invalid); // true
Example #3 – delete non deletable property
console.log(delete Math.PI); // false
'use strict' console.log(delete Math.PI); // In strict mode an exception is thrown

External references