Find One Item
Finds the first item matching specified criteria using optimized search strategies.
findOne()
Finds the first item matching specified criteria using optimized search strategies.
Signature
findOne(
matcher: string | number,
keySelector: KeySelector<T>,
options?: FindOptions<T>
): T | undefinedParameters
| Parameter | Type | Description |
|---|---|---|
matcher | string | number | Value to match against. |
keySelector | KeySelector<T> | Property name or value extractor function. |
options | FindOptions<T> | Search configuration options. |
Returns
T | undefined — First matching item or undefined if none found.
Example Usage
playground.ts
Behavior Details
- Cache First: Checks cache if
cacheKeyis provided. - Search Strategies:
- Linear search for small datasets (less than 100 items).
- Binary search for larger sorted datasets.
- Fuzzy search when enabled and no exact match.
- Result Caching: Stores successful finds when
cacheKeyis specified.
Notes
- Performance: Uses cache when available ($O(1)$ lookup). Falls back to linear search for small datasets ($O(n)$) or binary search for large sorted datasets ($O(\log n)$). Fuzzy search is $O(n)$ when enabled.
- Cache Behavior: Cache entries expire after 5 minutes by default. Cache is automatically cleared when the dataset changes.
- String Matching: Case-insensitive by default. Exact matching unless
fuzzyis true. - Sorting: Sorts data automatically when
needSortingis true. Skips sorting when data is already sorted.
Last updated: Mon, Jun 15, 2026 06:09:51AM (UTC)
