The findLast()
method of Array
instances iterates the array in reverse order and returns the value of the first element that satisfies the provided testing function. If no elements satisfy the testing function, undefined
is returned.
If you need to find:
- the first element that matches, use
find()
. - the index of the last matching element in the array, use
findLastIndex()
. - the index of a value, use
indexOf()
. (It's similar tofindIndex()
, but checks each element for equality with the value instead of using a testing function.) - whether a value exists in an array, use
includes()
. Again, it checks each element for equality with the value instead of using a testing function. - if any element satisfies the provided testing function, use
some()
.