Created
January 26, 2017 16:02
-
-
Save hejrobin/83e08865e137c615858439ee762138cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* 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