Skip to main content

findLast

Selects the last item from an array, collection or enumerable object that matches the truth function.

Signature

findLast<T>(
list: TList<T> | undefined,
fn: (item: T) => boolean
): T | undefined

Parameters

NameTypeOptionalDescription
listT[] | undefinedNoSpecifies the array, collection or enumerable object to iterate through.
fn(item: T) => booleanNoSpecifies the truth function. Each item is supplied to the function, passing the item as argument. The function should return a boolean value whether to include the item in the selection.

Return value

Returns the item or undefined if no item is found.

Example

import { findLast } from "@tripetto/runner";

findLast<number>([1, 2, 3], (nItem: number) => nItem > 1); // Returns `3`