Skip to content

Instantly share code, notes, and snippets.

@jaouadballat
Created February 28, 2020 09:59
Show Gist options
  • Save jaouadballat/2e9cbeac16cda959a301827f34d04fd2 to your computer and use it in GitHub Desktop.
Save jaouadballat/2e9cbeac16cda959a301827f34d04fd2 to your computer and use it in GitHub Desktop.
function omit(object, fields) {
const shallowObject = Object.assign({}, object);
if (typeof fields === Array) {
fields.forEach(field => {
if (!!shallowObject[field]) delete shallowObject[field];
});
return shallowObject;
} else if (typeof fields === "string") return delete shallowObject[fields];
else throw new Error(`fields ${fields} must be array or string`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment