My favorite way to create a new JavaScript object with a property omitted is...


My favorite way to create a new JavaScript object with a property omitted is Rest/spread.

// Create a user without the address property
const { address, ...userWithoutAddress } = user;

#javascript
This works for omitting multiple properties too.

// Create a user without the address property
const { address, password, ...userWithoutAddressOrPassword } = user;
Tip: If ESLint complains about an unused argument, slap an underscore on the front and it will ignore it. ๐Ÿ˜Ž

Or, if itโ€™s in a rest call, consider disabling the rest check: https://eslint.org/docs/rules/no-unused-vars#ignorerestsiblings

View original on X