Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created October 6, 2019 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NyaGarcia/2ba32b03d032c97d8c43ef1035b4aee6 to your computer and use it in GitHub Desktop.
Save NyaGarcia/2ba32b03d032c97d8c43ef1035b4aee6 to your computer and use it in GitHub Desktop.
Removing an object property dynamically with the rest parameter - ES6 version
const pokemon = {
useless: 'useless property',
id: 1,
name: 'Squirtle',
type: 'Water'
};
const remove = (property, { [property]: value, ...newObject }) => newObject;
console.log(remove('useless', pokemon)); // Result: { id: 1, name: 'Squirtle', type: 'Water' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment