• From object, pick a set of properties whose keys are in the keys array. This is an implementation of the Pick<T, K> type in TypeScript.

    Time complexity: O(n)

    Space complexity: O(n)

    Type Parameters

    • T
    • K extends string | number | symbol

    Parameters

    • object: T

      The object you are picking entries from

    • keys: readonly K[]

      The keys to keep from the object

    Returns Pick<T, K>

    A new object containing the picked entries

    Object

    const object = { a: 1, b: 2, c: 3 };

    pick(object, ['a', 'b']); // { a: 1, b: 2 }