Last active
May 29, 2021 15:15
-
-
Save TyT-NICK/76b2f95ba3561320ae8ba13aac948a99 to your computer and use it in GitHub Desktop.
Removing fields from object using Spread and Rest operators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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