Skip to main content
Module

std/collections/mod.ts>findLast

Deno standard library
Go to Latest
function findLast
Deprecated
Deprecated

Use Array.prototype.findLast. This function will be removed in std@0.117.0.

Returns the last element in the given array matching the given predicate

Example:

import { findLast } from "https://deno.land/std@0.114.0/collections/mod.ts";
import { assertEquals } from "https://deno.land/std@0.114.0/testing/asserts.ts";

const numbers = [ 4, 2, 7 ]
const lastEvenNumber = findLast(numbers, it => it % 2 === 0)

assertEquals(lastEvenNumber, 2)
import { findLast } from "https://deno.land/std@0.114.0/collections/mod.ts";

Parameters

array: readonly T[]
predicate: (el: T) => boolean

Returns

T | undefined