Javascript programming articles and tutorials for beginner | Anjan Dutta

Javascript remove object property

Javascript remove object property

We can use the delete keyword to remove property from object in javascript. It will reove the specified object property completely leaving the rest of the properties unchanged.

let fruitObject = { name: 'Apple', color: 'Red' }
delete fruitObject.color;
// { name: 'Apple' }

Exception

The only case if the property is created using defineProperty and configurable is false then delete will not work.

So, make sure to check this before deleting any property.

See below example, the configurable: true lets us remove the property from the object.

object remove property

But, in the next example, the configurable: false ensures we can't remove the property.

While trying to delete the property here, we are getting a false response and further printing the object gave us the response unchanged.

object remove property false

Edit this page on GitHub