Destructure an object to remove a property

profile
Tim Deschryver
timdeschryver.dev

Destructure an object to remove a property link

Use case link

I want to delete a property from an object in a pure (immutable) way.

Solution link

Use a destructuring assignment to assign the to be removed property to a variable, while cloning the "rest" properties to a new variable. The _ is used to prevent a linter giving the warning "variable is declared but its value is never read".

For more examples see Destructuring assignment on MDN

Feel free to update this blog post on GitHub, thanks in advance!

Join My Newsletter (WIP)

Join my weekly newsletter to receive my latest blog posts and bits, directly in your inbox.

Support me

I appreciate it if you would support me if have you enjoyed this post and found it useful, thank you in advance.

Buy Me a Coffee at ko-fi.com PayPal logo

Share this post on

Twitter LinkedIn