Skip to main content

pickBy

Similar to the pick function, but returns a new object composed of properties from the given object that satisfy the predicate function.


Code

🔗 View source code

Benchmark

  • hz: operations per second
  • mean: average response time (ms)
NamehzmeanPerformance
modern-kit/pickBy7,602,665.150.0001fastest
lodash/pickBy1,768,814.920.0006slowest
  • modern-kit/pickBy
    • 4.30x faster than lodash/pickBy

Interface

typescript
function pickBy<T extends Record<PropertyKey, any>>(
obj: T,
predicate: (value: T[keyof T], key: keyof T) => boolean
): Partial<T>;

Usage

typescript
import { pickBy } from '@modern-kit/utils';

const obj = { a: 1, b: undefined, c: null, d: '', e: 'str' };
const result = pickBy(obj, (value) => !value);
// { b: undefined, c: null, d: '' }