Omit properties from an object

Keep the own enumerable fields that are not in a supplied list.

JavaScript Version 1.0.0 · MIT · .md

omit-a-subset-of-properties-from-an-object.js
function omit({ value, keys }) { return Object.fromEntries(Object.entries(value).filter(([key]) => !keys.includes(key))); }

Input & expected output

Input

{
  "value": {
    "content-type": "application/json",
    "idempotency-key": "order-confirmation:8812:1",
    "authorization": "Bearer $OVEYON_API_KEY"
  },
  "keys": [
    "authorization"
  ]
}

Expected output

{
  "content-type": "application/json",
  "idempotency-key": "order-confirmation:8812:1"
}

The edge case

Input

{
  "value": {},
  "keys": [
    "a"
  ]
}

Expected output

{}

Know the limits

  • This copies enumerable string-keyed properties only. Values remain shared.
  • Do not use a denylist alone to filter confidential fields for an API response.

The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.

Source & maintenance

Based on Omit a subset of properties from an object from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.

Curated implementation; explicit input bounds, edge cases, local fixtures and rebuilt presentation. Original MDX retained as inert source evidence.

Maintained by Oveyon. Source commit: 14b481cf60df. Read the license.

Local fixture scope · Node.js 22.23.2 · reviewed October 28, 2026. No external service is required.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.