VOOZH about

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

⇱ Lodash _.sortedLastIndex() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.sortedLastIndex() Method

Last Updated : 2 Sep, 2024

Lodash _.sortedLastIndex() method is used to return the highest index of the array where an element can be inserted and maintain its sorted order.

Syntax:

_.sortedLastIndex(array, value);

Parameters:

  • array: This parameter holds the sorted array.
  • value: This parameter holds the value to evaluate.

Return Value:

  • This method returns the index at which the value should be inserted into the array.

Example 1: In this example, we are finding the index at which we can put the given value into the given array by the use of the lodash _.sortedLastIndex() method.

Output:

6

Example 2: In this example, we are finding the index at which we can put the given value into the given array by the use of the lodash _.sortedLastIndex() method.

Output:

7

Example 3: In this example, we are finding the index at which we can put the given value into the given array by the use of the lodash _.sortedLastIndex() method.

Output:

5

Note: This will not work in normal JavaScript because it requires the library lodash to be installed.

Comment