# How to remove a property from an object in JavaScript

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Jul 3, 2020, updated Aug 5, 2020. Topics: JavaScript.
Canonical URL: https://attacomsian.com/blog/javascript-object-remove-property

> A quick article to learn how to remove a property from an object in JavaScript.

In an earlier article, we looked at how to [add a property](https://attacomsian.com/blog/javascript-object-add-key) to an object in JavaScript. But what if you want to remove a specific property from an object?

JavaScript provides the `delete` operator to remove a property from an [object](https://attacomsian.com/blog/objects-prototypes-classes-javascript#objects). On successful deletion, it will return `true`, otherwise `false`:

```javascript
const foods = { burger: '?', pizza: '?', cake: '?' };

// Dot Notatation
delete foods.pizza;

// OR

// Square Bracket Notation
delete foods['pizza'];

console.log(foods);
// { burger: '?', cake: '?' }
```

The `delete` operator works with both dot notation (`.`) as well as square bracket (`[]`) notation. 

When using the `delete` operator, you should consider the following scenarios:

* If the property which you are trying to delete does not exist, delete will do nothing and will simply return `true`.
* If a property with the same name exists on the [object's prototype](https://attacomsian.com/blog/objects-prototypes-classes-javascript#prototypes) chain, then, after deletion, the object will use the property from the prototype chain. In other words, `delete` only removes properties from the object's own properties and has no effect on the object's prototype properties.
* Any property declared with `let` or `const` cannot be deleted from the scope within which they were defined.

Take a look at this [MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete) to learn more about the `delete` operator in JavaScript.
