Lodash - sortedLastIndexBy 方法



語法

_.sortedLastIndexBy(array, value, [iteratee=_.identity])

此方法類似於 _.sortedLastIndex,但它接收按值呼叫的 iteratee 和陣列的每個元素以計算其排序排名。使用一個引數呼叫 iteratee:(value)。

引數

  • array (陣列)- 要檢查的已排序陣列。

  • value (*)- 要計算的值。

  • [iteratee=_.identity] (函式)- 按元素呼叫的 iteratee。

輸出

  • (數字)- 返回應將值插入 array 中的索引。

示例

var _ = require('lodash');
var list = [{ 'x': 4 }, { 'x': 1 }];

var result = _.sortedLastIndexBy(list, [{ 'x': 4 }], 'x');
console.log(result);

將上述程式儲存在 tester.js 中。執行以下命令以執行此程式。

命令

\>node tester.js

輸出

2
lodash_array.htm
廣告
© . All rights reserved.