offline version v3


114 of 264 menu

findLast method

The findLast method searches for the first element from the end of an array according to the callback parameter. If there is no element, then undefined is returned.

Syntax

array.findLast(function);

Example

Let's find the element of an array that matches the conditions specified in a function:

let arr = [1, 2, 3, 4, 5]; let res = arr.findLast(function(elem) { return elem > 0; }); console.log(res);

The code execution result:

5

See also

  • the find method
    that searches for an element in an array
  • the findIndex method
    that searches for the index of an element in an array
  • the findLastIndex method
    that searches for the index of an element from the end of an array
enru