VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-lastindexof-method/

⇱ Lodash _.lastIndexOf() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.lastIndexOf() Method

Last Updated : 15 Jul, 2025

Lodash _.lastIndexOf() method is like the _.indexOf method except that it iterates over elements of an array from right to left.

Syntax:

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

Note: If the value is not found in the array -1 is returned.

Parameters:

  • array: It is the array in which value is to be found.
  • value: It is the value to be looked at in the array.
  • fromIndex: It is the index after which we have to look for the value.

Return Value:

  • It returns the index of the value in the array. If the value is not found, the array returns -1.

Example 1: In this example, we are finding the index of the 2 in a given array by the use of the _lastIndexOf() method.

Output:

👁 Image

Example 2: In this example, we are finding the index of the 2 from 2 index number in a given array by the use of the _lastIndexOf() method.

Output:

👁 Image

Example 3: In this example, we are finding the index of the 4 in a given array by the use of the _lastIndexOf() method and it is returning -1 as it is not present in that array.

Output:

👁 Image
Comment