Function objPick

  • Returns a new object with the specified keys from a source object

    Example

    const obj = {
    "one": true,
    "two": false,
    "foo": "bar"
    };

    const newObj = objPick(obj, ['two', 'foo']);
    =>
    {
    "two": false,
    "foo": "bar"
    }

    Type Parameters

    • Type extends Record<string | number | symbol, unknown>

    • Key extends string | number | symbol

    Parameters

    • a: Type

      An object

    • keys: string[] | Key[]

      An array of keys to pick

    • Optional options: {
          defaultValue?: unknown;
          upsert?: boolean;
      }

      Optional options

      • Optional defaultValue?: unknown

        Default value to use when upsert-ing

      • Optional upsert?: boolean

        Whether to create new properties for missing keys

    Returns Record<string | Key, Type[keyof Type]>

Generated using TypeDoc