🧩 Finds the index of the last item that matches a predicate.

Syntax

TypeScript
import { findLastIndexIter } from '@opentf/std';

findLastIndexIter<T>(iter: Iterable<T>, fn: (val: T) => boolean): number

Parameters

  • iter: The source iterable.

  • fn: The predicate function.

Returns

The index of the last matching item, or -1.

Examples

TypeScript
findLastIndexIter([1, 2, 3, 2], (x) => x === 2) //=> 3
Last updated on
Edit this page