Tim Deschryver

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

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
Support the blog Share on Twitter Discuss on Twitter Edit on GitHub