lastIndexOf source npm

_.lastIndexOf(array, value, [fromIndex=array.length-1])

This method is like _.indexOf except that it iterates over elements of array from right to left.

Arguments

  1. array (Array)

    The array to search.

  2. value (*)

    The value to search for.

  3. [fromIndex=array.length-1] (number)

    The index to search from.

Returns (number)

Returns the index of the matched value, else -1.

Example

_.lastIndexOf([1, 2, 1, 2], 2);
// => 3

// using `fromIndex`
_.lastIndexOf([1, 2, 1, 2], 2, 2);
// => 1