-
-
Save sentience/f8bd15cdd37165ca40e0 to your computer and use it in GitHub Desktop.
Underscore.js mixing to remove one or more keys from an 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
// remove key from object | |
_.mixin({ | |
remove: function(obj, keys){ | |
return _.chain([keys]).flatten().reduce(function(obj, key){ | |
delete obj[key]; | |
return obj; | |
}, obj).value(); | |
} | |
}); |
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
# remove key(s) from object | |
_.mixin | |
remove: (obj, keys) -> | |
_.chain([keys]).flatten().reduce( | |
(obj, key) -> | |
delete obj[key]; obj | |
, obj).value() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment