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
findmethod
that searches for an element in an array -
the
findIndexmethod
that searches for the index of an element in an array -
the
findLastIndexmethod
that searches for the index of an element from the end of an array