Function pickObjectProps

  • Pick specific properties from an object.

    This function creates a new object composed of the properties listed in the keys array, extracted from the source object.

    Example

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

    Example

    const user = { name: 'John', age: 30, email: 'john@example.com' };
    const picked = pickObjectProps(user, ['name', 'email']);
    // => { name: 'John', email: 'john@example.com' }

    Type Parameters

    • T extends Record<string, any>

    • K extends string | number | symbol

    Parameters

    • source: T

      The source object from which to pick properties.

    • keys: K[]

      An array of keys that should be picked from the source object.

    Returns Pick<T, K>