Toolbox-XToolbox-X

Find All Items

Finds all items matching specified criteria using optimized search strategies.

findAll()

Finds all items matching specified criteria using optimized search strategies.

Signature

findAll(
  matcher: string | number,
  keySelector: KeySelector<T>,
  options?: FindOptions<T>
): T[]

Parameters

ParameterTypeDescription
matcherstring | numberValue to match against.
keySelectorKeySelector<T>Property name or value extractor function.
optionsFindOptions<T>Search configuration options.

Returns

T[] — Array of all matching items (empty array if none found).

Example Usage

playground.ts

Behavior Details

  1. Search Flow:

    • Checks cache first if cacheKey is provided.
    • Uses linear search for small datasets (less than 100 items).
    • Uses binary search for larger sorted datasets.
    • Falls back to fuzzy search when enabled.
  2. Result Handling:

    • Returns all matches (not just the first one).
    • Maintains the original item order in results.
    • Returns an empty array if no matches are found.
  3. Performance:

    • Cached results: $O(1)$
    • Linear search: $O(n)$
    • Binary search: $O(\log n) + O(m)$ where $m$ is the number of matches.
    • Fuzzy search: $O(n)$

Notes

  • Cache Behavior: Results are cached for 5 minutes by default. The cache is automatically cleared when the dataset changes.
  • String Matching: Case-insensitive by default. Exact matching unless fuzzy is enabled.
  • Sorting: Auto-sorts when needSorting is true. Skips sorting for pre-sorted data. Natural key order is used.
  • Edge Cases: Empty input returns an empty array. Handles null/undefined in data. Works with both numeric and string keys.

Last updated: Mon, Jun 15, 2026 06:09:51AM (UTC)

On this page