Skip to content

pickBy

pickBy<T, Predicate>(obj, predicate): Partial<T>

Create a new object with all the properties for which the predicate hold true.

Example

pickBy({foo: 1, bar: "foo"}, ([, v]) => isNumber(v))
// => {foo: 1}

Alternatives

Type Parameters

T extends object | ArrayLike<unknown>

Predicate extends (__namedParameters) => boolean

Parameters

obj

T

The object to take the properties from.

predicate

Predicate

The function that must hold true for the property to be included.

Returns

Partial<T>

The constructed object.