Skip to content

Instantly share code, notes, and snippets.

@jasonphillips
Created November 9, 2017 17:24
Show Gist options
  • Save jasonphillips/89f42cf6096a62cae2c22abcd0da167e to your computer and use it in GitHub Desktop.
Save jasonphillips/89f42cf6096a62cae2c22abcd0da167e to your computer and use it in GitHub Desktop.
omit "One"-liner
const omit = (obj, omitProps) => Object.keys(obj)
.filter(key => omitProps.indexOf(key)===-1)
.reduce((returnObj, key) => ({ ...returnObj, [key]: obj[key] }), {})
const myObject = {a:'1', b:'2', c:'3', d:'4'}
omit(myObject, ['a','c'])
// Object {b: "2", d: "4"}
omit(myObject, ['a'])
// Object {b: "2", c: "3", d: "4"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment