Created
October 2, 2018 12:59
-
-
Save matheus-santos/9ec9a418296fcaca21ec6a587733ee93 to your computer and use it in GitHub Desktop.
Lodash: Delete unwanted properties from the javascript object
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
You can approach it from either a white list or black list way: | |
// Black list | |
// Remove the values you don't want | |
var result = _.omit(credentials, ['age']); | |
// White list | |
// Only allow certain values | |
var result = _.pick(credentials, ['fname', 'lname']); | |
If it's reusable business logic, you can partial it out as well: | |
// Partial out a black list version | |
var clean = _.partial(_.omit, _, ['age']); | |
// and later | |
var result = clean(credentials); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment