Array.prototype.findLast()

Returns the last element that satisfies the provided testing function, iterating from the end.

Since ES2023 Spec ↗

Syntax

arr.findLast(callback, thisArg)

Parameters

NameTypeRequiredDescription
callback Function Yes Predicate called with (element, index, array). Return truthy to select the element.
thisArg any No Value to use as `this` when executing the callback.

Returns

any — The last matching element, or undefined if none match.

Examples

const nums = [5, 12, 8, 130, 44];
console.log(nums.findLast(n => n > 10));
Output
44
console.log([1, 2, 3].findLast(n => n > 9));
Output
undefined

Notes

Iterates from the highest index to the lowest. Returns undefined when nothing matches. Use `findLastIndex` to get the position. Does not mutate the array.

Browser & runtime support

EnvironmentSince version
chrome 97
firefox 104
safari 15.4
edge 97
node 18

See also