Omit object properties

OSCC · JavaScript, Object · Oct 21, 2020

Omits the key-value pairs corresponding to the given keys from an object.

const omit = (obj, arr) =>
  Object.keys(obj)
    .filter(k => !arr.includes(k))
    .reduce((acc, key) => ((acc[key] = obj[key]), acc), {});
omit({ a: 1, b: '2', c: 3 }, ['b']); // { 'a': 1, 'c': 3 }

Recommended snippets