Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

delete

Removes a property from an object.

Available since: ES1

Syntax

delete object.property

Examples

Removing a property:

const user = { name: 'Anna', password: 'secret' };
 
delete user.password;
 
console.log(user);

Output:

{
  "name": "Anna"
}

Without changing the object — destructuring with rest:

const user = { name: 'Anna', password: 'secret' };
const { password, ...publicUser } = user;
 
console.log(publicUser);

Output:

{
  "name": "Anna"
}

Notes

delete is not for array elements: it leaves a hole and the length stays the same. Use splice() or filter(). Variables cannot be deleted.

See also

In the tutorial

  • Objects — Objects in JavaScript: properties, dot and bracket access, adding, deleting and nested data.

Thanks for reading!

Donate to the site — we work hard for you.