findLastKey
Returns the last key in an object that satisfies the given condition.
Code
Benchmark
hz: operations per secondmean: average response time (ms)
| Name | hz | mean | Performance |
|---|---|---|---|
| modern-kit/findLastKey | 19,157,255.73 | 0.0001 | fastest |
| lodash/findLastKey | 7,387,616.57 | 0.0001 | slowest |
- modern-kit/findLastKey
2.59xfaster 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'