Last Updated : 15 Jul, 2025
Lodash _.sortedUniqBy method is used to return the lowest index of the array where an element can be inserted and maintain its sorted order. Also, this method is like _.uniqBy except that it's designed and optimized for sorted arrays.
Syntax:_.sortedUniqBy(array, [iteratee]);Parameters:
This method is used to return the new duplicate free array.
Example 1: In this example, we are getting an array that has unique elements by the use of the lodash _.sortedUniqBy() method.
javascript
// Requiring the lodash library
const _ = require("lodash");
// Original array
let y = ([1.1, 1.2, 2.1, 2.3, 2.4, 3.5])
// Use of _.sortedUniqBy()
// method
let index = _.sortedUniqBy(y, Math.floor);
// Printing the output
console.log(index);
Output:
[1.1, 2.1, 3.5]
Example 2: In this example, we are getting an array that has unique elements by the use of the lodash _.sortedUniqBy() method.
javascript
// Requiring the lodash library
const _ = require("lodash");
// Original array
let y = ([112.1, 112.2, 122.1, 122.3, 122.4, 132.5])
// Use of _.sortedUniqBy()
// method
let index = _.sortedUniqBy(y, Math.floor);
// Printing the output
console.log(index);
Output:
[112.1, 112.1, 132.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