pick

Commons
stable

Extract a subset of an object's own enumerable keys into a new object. Only keys that actually exist on `obj` are included — missing keys are silently skipped (contrast with `only`, which copies all listed keys unconditionally).

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

obj
required
T
The source object to extract properties from.
paths
required
Array<U>
Array of key names to include. Only keys that exist in the source object (checked via `Object.keys`) are copied; absent keys are skipped.

API

Return value

The value returned by this util.

A new object with only the requested keys that were present on the source. Does not mutate the original.

Usage

Examples

Ready-to-paste usage snippets.

Extract known keys from an object

typescript