![]() |
VOOZH | about |
Lodash _.sortedIndexBy() method is used to return the lowest index of the array where an element can be inserted and maintain its sorted order. In addition, it accepts iteratee which is invoked for value and each element of the array to compute their sort ranking. It uses the binary search.
_.sortedIndexBy(array, value, [iteratee=_.identity]);Example 1: In this example, we are getting the index at which we can insert the given value.
Output:
1Example 2: In this example, we are getting the index at which we can insert the given value.
Output:
2Example 3: In this example, we are getting the index at which we can insert the given value.
Output:
3Note: This will not work in normal JavaScript because it requires the library lodash to be installed.