Function pick

  • Creates a new object by including 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.

    Parameters

    • obj: Readonly<T>

      The object to pick keys from.

    • keys: readonly K[]

      The keys to include in the new object.

    Returns Pick<T, K>

    A new object with the specified keys from the provided object.

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

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

    assertEquals(picked, { a: 5, c: 7 });