Omit properties from an object
Keep the own enumerable fields that are not in a supplied list.
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.
Keep exploring
- Pick properties from an object — Build a new object with only the requested own properties.
- Create an object from pairs of key and value — Turn [key, value] pairs into a plain object with Object.fromEntries.
- Check if multiple objects are equal — Compare JSON serializations with the first object.