본문으로 건너뛰기

findLastKey

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


Code

🔗 실제 구현 코드 확인

Benchmark

  • hz: 초당 작업 수
  • mean: 평균 응답 시간(ms)
이름hzmean성능
modern-kit/findLastKey19,157,255.730.0001fastest
lodash/findLastKey7,387,616.570.0001slowest
  • modern-kit/findLastKey
    • 2.59x faster than lodash/findLastKey

Interface

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

Usage

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

const obj = {
bike: { active: true },
car: { active: false },
plane: { active: true },
};
findLastKey(obj, (item) => item.active); // 'plane'