VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-findlastindex-function/

⇱ Lodash _.findLastIndex() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.findLastIndex() Function

Last Updated : 2 Sep, 2024

Lodash _.findLastIndex() function is used to find the element from the right of the array. Therefore giving the index of the last occurrence of the element in the array.

Syntax:

findLastIndex(array, [predicate=_.identity], fromIndex);

Parameters:

  • array: It is the original array.
  • predicate: It is the function that iterates over each element.
  • fromIndex: It is the index after which the search starts. If from Index is not given then by default it is n-1 where n is the length of the array.

Return Value:

It returns the index of the element if found else -1 is returned.

Example 1: In this example, we are getting the last index of element 2 that is present in the given array by the use of the lodash _.findLastIndex() function.

Output:

👁 Image

Example 2: In this example, we are using the lodash _.findLastIndex() functionand getting "-1" as the element 1 is not present in the given array.

Output:

👁 Image

Example 3: In this example, we are getting the last index of element 2 that is present in the given array of objects by the use of the lodash _.findLastIndex() function.

Output:

👁 Image
Comment