Last Updated : 02 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:
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.
javascript
const _ = require('lodash');
let x = [1, 2, 3, 4, 4, 4, 5, 6, 6]
let index = _.sortedLastIndex(x, 4);
console.log(index);
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.
javascript
const _ = require('lodash');
let x = ['a', 'b', 'c', 'd', 'e', 'e', 'e', 'f']
let index = _.sortedLastIndex(x, 'e');
console.log(index);
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.
javascript
const _ = require('lodash');
let x = ['ajax', 'django', 'mongoDb',
'react', 'reactnative', 'yarn']
let index = _.sortedLastIndex(x, 'ruby');
console.log(index);
Output:
5
Note: This will not work in normal JavaScript because it requires the library lodash to be installed.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4