Omit object keys

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 }

More like this

  • JavaScript Object Key Selection

    Pick and omit keys from JavaScript objects easily, using the snippets in this collection.

    Collection · 4 snippets

  • Pick object keys

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

    JavaScript, Object · Oct 18, 2020

  • Omit matching object keys

    Creates an object composed of the properties the given function returns falsy for.

    JavaScript, Object · Oct 21, 2020

  • Pick matching object keys

    Creates an object composed of the properties the given function returns truthy for.

    JavaScript, Object · Oct 22, 2020