Removing Object Properties with Destructuring

added 04.06.2020 11:40

Image of article 'Removing Object Properties with Destructuring'

In this post you’ll learn how to remove properties from an object in JavaScript using destructuring and the syntax.

Object destructuring allows us to create variables from object property names, and the variable will contain the value of the property name - for example: By using we are declaring 3 new variables ( , and ).

Here’s how we would do this without object destructuring or the rest syntax, it’s a lot more tedious and doesn’t allow us to dynamically get all remaining properties: Let’s say we have a key that perhaps a user has supplied that they want to delete.

However, at this point we can again introduce the rest syntax to remove the property from the object: There you have it, we’ve successfully deleted a property dynamically in JavaScript using object destructuring and the rest syntax!

We’ve used object destructuring and looked at how to combine it with the rest syntax to give us a clean solution to removing object properties.