Skip to main content

findKey

객체에서 조건에 부합하는 key를 반환합니다.

Code

🔗 실제 구현 코드 확인

Benchmark

  • hz: 초당 작업 수
  • mean: 평균 응답 시간(ms)
이름hzmean성능
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,
condition: (value: T[keyof 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'