Skip to content

Instantly share code, notes, and snippets.

@matheus-santos
Created October 2, 2018 12:59
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 matheus-santos/9ec9a418296fcaca21ec6a587733ee93 to your computer and use it in GitHub Desktop.
Save matheus-santos/9ec9a418296fcaca21ec6a587733ee93 to your computer and use it in GitHub Desktop.
Lodash: Delete unwanted properties from the javascript object
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