Skip to content

omit

Creates a new object without the specified keys.

Available since v2.0.0

import { omit } from '@helpers4/object';
omit<T extends Record<string, unknown>, K extends string | number | symbol>(obj: T, keys: readonly K[]): Omit<T, K>
ParameterTypeDescription
objTThe source object
keysreadonly K[]The keys to omit

Omit<T, K> — A new object without the omitted keys

Creates a new object without the specified keys.

omit({ a: 1, b: 2, c: 3 }, ['b'])
// => { a: 1, c: 3 }

Useful to strip sensitive data before sending to client.

const user = { id: 1, name: 'Alice', password: 'secret', token: 'abc123' };
omit(user, ['password', 'token'])
// => { id: 1, name: 'Alice' }

View source on GitHub