Skip to main content

findKey

Returns the first key in an object that satisfies the given condition.


Code

🔗 View source code

Benchmark

  • hz: operations per second
  • mean: average response time (ms)
NamehzmeanPerformance
modern-kit/findKey18,629,221.400.0001fastest
lodash/findKey6,807,578.650.0001slowest
  • modern-kit/findKey
    • 2.74x faster than lodash/findKey

Interface

typescript
function findKey<T extends Record<PropertyKey, any>>(
obj: T,
predicate: (predicateData: {
value: T[keyof T];
key: keyof T;
obj: T;
}) => boolean
): string | undefined;

Usage

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

const obj = {
bike: { active: true },
plane: { active: true },
car: { active: false },
};

findKey(obj, (item) => item.active); // 'bike'