![]() |
VOOZH | about |
Lodash _.sortedIndexOf() method is used to get the index of the first occurrence of the particular element in the sorted array. It uses the binary search to sort an array.
_.sortedIndexOf(array, value);Example 1: In this example, we are getting the index at which we got the given value in the given array.
Output:
3Example 2:In this example, we are getting the index at which we got the given value in the given array.
Output:
4Example 3: In this example, we are getting -1 as the index because the given value is not present in the given array.
Output:
-1Note: This will not work in normal JavaScript because it requires the library lodash to be installed.