Function omit

  • Creates a new object by excluding the specified keys from the provided object.

    Type Parameters

    • T extends object

      The type of the object.

    • K extends string | number | symbol

      The type of the keys to omit.

    Parameters

    • obj: Readonly<T>

      The object to omit keys from.

    • keys: readonly K[]

      The keys to omit from the object.

    Returns Omit<T, K>

    A new object with the specified keys omitted.

    import { omit } from "@std/collections/omit";
    import { assertEquals } from "@std/assert";

    const obj = { a: 5, b: 6, c: 7, d: 8 };
    const omitted = omit(obj, ["a", "c"]);

    assertEquals(omitted, { b: 6, d: 8 });