pickBy
Creates a new object with only the own enumerable entries for which
predicate returns true.
Complements pick for when the keys to keep aren’t known ahead of
time — pick takes an explicit key list, pickBy takes a predicate.
Available since v3.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
obj | T | null | undefined | The source object. `null`/`undefined` pass through unchanged. |
predicate | function | Called with `(value, key)` for each own enumerable entry |
Returns
Section titled “Returns”Partial<T> | null | undefined — A new object with only the matching entries
Examples
Section titled “Examples”Keep only entries matching a predicate
Section titled “Keep only entries matching a predicate”Unlike pick(), the keys to keep don’t need to be known ahead of time.
Keep entries by key name
Section titled “Keep entries by key name”The predicate also receives the key, so filtering by name works too.
