Menu

gitpiper

omit javascript Code Snippet in 2024

objectintermediate

Last Updated: 13 July 2024

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

  • Use Object.keys(), Array.prototype.filter() and Array.prototype.includes() to remove the provided keys.
  • Use Array.prototype.reduce() to convert the filtered keys back to an object with the corresponding key-value pairs.
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 }

javascript snippet similar to omit For You in July 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️