Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function findLastIndex
Deprecated
Deprecated

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

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

Example:

import { findLastIndex } 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 lastIndexNumber = findLastIndex(numbers, it => it % 2 === 0)

assertEquals(lastIndexNumber, 1)
import { findLastIndex } from "https://deno.land/std@0.114.0/collections/find_last_index.ts";

Parameters

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

Returns

number | undefined