Skip to main content

omitBy

Similar to the omit function, but returns a new object excluding 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/omitBy9,108,836.710.0001fastest
lodash/omitBy1,876,976.550.0005slowest
  • modern-kit/omitBy
    • 4.85x faster than lodash/omitBy

Interface

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

Usage

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

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