Skip to content

sortedIndexBy

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

此方法类似于 _.sortedIndex,只是它接受 iteratee,后者为 valuearray 的每个元素调用以计算它们的排序排名。迭代器使用一个参数调用:(value)。

¥This method is like _.sortedIndex except that it accepts iteratee which is invoked for value and each element of array to compute their sort ranking. The iteratee is invoked with one argument: (value).

新增于

¥Since

4.0.0

参数

¥Arguments

  1. array (数组):要检查的排序数组。

    ¥array (Array): The sorted array to inspect.

  2. value (*):要评估的值。

    ¥value ()*: The value to evaluate.

  3. [iteratee=_.identity] (函数):每个元素调用迭代器。

    ¥[iteratee=_.identity] (Function): The iteratee invoked per element.

返回

¥Returns

(数值):返回应将 value 插入 array 的索引。

¥(number): Returns the index at which value should be inserted into array.

示例

¥Example

js
var objects = [{ 'x': 4 }, { 'x': 5 }];

_.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
// => 0

// The `_.property` iteratee shorthand.
_.sortedIndexBy(objects, { 'x': 4 }, 'x');
// => 0

Lodash v4.17 中文网 - 粤ICP备13048890号