Skip to content

Instantly share code, notes, and snippets.

@TyT-NICK
Last active May 29, 2021 15:15
Show Gist options
  • Save TyT-NICK/76b2f95ba3561320ae8ba13aac948a99 to your computer and use it in GitHub Desktop.
Save TyT-NICK/76b2f95ba3561320ae8ba13aac948a99 to your computer and use it in GitHub Desktop.
Removing fields from object using Spread and Rest operators
const removeFieldsFromObject = (obj, ...fieldNames) => {
let newObj = { ...obj };
fieldNames.forEach((x) => {
const { [x]: removed, ...rest } = newObj;
newObj = rest;
});
return newObj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment