Created
March 1, 2019 07:27
-
-
Save joelnet/d8ef09c15d83485cf684e98ca1e55735 to your computer and use it in GitHub Desktop.
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 user1 = { | |
id: 100, | |
name: 'Howard Moon', | |
password: 'Password!' | |
} | |
const removeProperty = prop => ({ [prop]: _, ...rest }) => rest | |
// ---- ------ | |
// \ / | |
// dynamic destructuring | |
const removePassword = removeProperty('password') | |
const removeId = removeProperty('id') | |
removePassword(user1) //=> { id: 100, name: 'Howard Moon' } | |
removeId(user1) //=> { name: 'Howard Moon', password: 'Password!' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@dv, actually you can substitute _ with any valid variable name. The idea here is to take the [prop] of an object, encapsulate it inside the function and return only rest.