_.sortedUniqBy方法用於返回可以插入元素的數組的最低索引,並保持其排序順序。此外,此方法類似於_.uniqBy,但它是為排序數組設計和優化的。
用法:
_.sortedUniqBy(array, [iteratee])
參數:該方法接受上述和以下所述的兩個參數:
- array:此參數保存要檢查的數組。
- [iteratee = _。identity](函數):此參數保存每個元素調用的iteratee。
返回值:此方法用於返回新的重複自由數組。
範例1:在這裏,const _ = require(‘lodash’)用於將lodash庫導入文件中。
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);
輸出:
[1.1, 2.1, 3.5]
範例2:
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);
輸出:
[112.1, 112.1, 132.5]
注意:在正常的JavaScript中這將無法正常工作,因為它需要安裝庫lodash。
相關用法
- Lodash _.every()用法及代碼示例
- Lodash _.xor()用法及代碼示例
- Lodash _.last()用法及代碼示例
- Lodash _.take()用法及代碼示例
- Lodash _.max()用法及代碼示例
- Lodash _.min()用法及代碼示例
- Lodash _.add()用法及代碼示例
- Lodash _.zip()用法及代碼示例
- Lodash _.nth()用法及代碼示例
- Lodash _.pull()用法及代碼示例
- Lodash _.xorBy()用法及代碼示例
- Lodash _.indexOf()用法及代碼示例
- Lodash _.startCase()用法及代碼示例
- Lodash _.castArray()用法及代碼示例
- Lodash _.differenceWith()用法及代碼示例
- Lodash _.isSymbol()用法及代碼示例
- Lodash _.cloneDeep()用法及代碼示例
- Lodash _.startsWith()用法及代碼示例
- Lodash _.fromPairs()用法及代碼示例
- Lodash _.takeRight()用法及代碼示例
注:本文由純淨天空篩選整理自shivanisinghss2110大神的英文原創作品 Lodash _.sortedUniqBy() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。