Skip to content

Instantly share code, notes, and snippets.

@hejrobin
Created January 26, 2017 16:02
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 hejrobin/83e08865e137c615858439ee762138cf to your computer and use it in GitHub Desktop.
Save hejrobin/83e08865e137c615858439ee762138cf to your computer and use it in GitHub Desktop.
/**
* Object.omit
*
* Returns a (shallow) copy of an object, with specified keys omitted.
*
* @param object sourceObject
* @param string omitKeys, ...
*
* @return object
*/
Object.omit = (sourceObject, ...omitKeys) => {
let filteredObject = Object.assign({}, sourceObject);
omitKeys.forEach(omitKey => {
if (Object.keys(sourceObject).indexOf(omitKey) > -1) {
delete filteredObject[omitKey];
}
});
return filteredObject;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment