Skip to main content

findLastKey

Returns the last 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/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'