Skip to content

Instantly share code, notes, and snippets.

@lstebner
Created August 31, 2012 23:44
Show Gist options
  • Save lstebner/3561250 to your computer and use it in GitHub Desktop.
Save lstebner/3561250 to your computer and use it in GitHub Desktop.
Underscore mixin to delete an object property
// remove key from object
_.mixin({
remove: function(obj, key){
delete obj[key];
return obj;
}
});
@sjogren
Copy link

sjogren commented Mar 20, 2015

Cool! Would be nice if you could also pass in an array of property names or any number of arguments to be deleted.

_.remove(obj, ['my', 'keys', 'to', 'delete']);
_.remove(obj, 'my', 'keys', 'to', 'delete');

@sentience
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment