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

javascriptarray.findLast(function);

Example

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

javascriptlet arr = [1, 2, 3, 4, 5];

let res = arr.findLast(function(elem) {
  return elem > 0;
});

console.log(res);

The code execution result:

javascript5

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