Skip to main content

pick

Callable

  • pick<T, K>(obj: T, keys: readonly K[]): Simplify<Pick<T, K>>

  • It takes an object and an array of keys, and returns a new object with only those keys.

    Example

    pick({foo: "bar", bar: "foo"}, ["foo"])
    // => {foo: "bar"}

    pick({foo: "bar", bar: "foo"}, [])
    // => {}

    Alternatives


    Type parameters

    • T: object | ArrayLike<unknown>
    • K: string | number | symbol

    Parameters

    • obj: T

      The object to take the properties from.

    • keys: readonly K[]

      The keys to select on the object.

    Returns Simplify<Pick<T, K>>

    The constructed object.