es-toolkit/docs/reference/object/omit.md
Jun 79ce446a51
fix(pick, omit): Restrict the type of arguments in object utils (#35)
* feat: change object utils type def

Co-authored-by: 김관식 <39869096+gwansikk@users.noreply.github.com>

* docs: modify object utils docs

---------

Co-authored-by: 김관식 <39869096+gwansikk@users.noreply.github.com>
2024-06-12 15:22:16 +09:00

666 B

omit

Creates a new object with specified keys omitted.

This function takes an object and an array of keys, and returns a new object that excludes the properties corresponding to the specified keys.

Signature

function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;

Parameters

  • obj (T): The object to omit keys from.
  • keys (K[]): An array of keys to be omitted from the object.

Returns

(Omit<T, K>): A new object with the specified keys omitted.

Examples

const obj = { a: 1, b: 2, c: 3 };
const result = omit(obj, ['b', 'c']);
// result will be { a: 1 }