主题
sortedIndexBy
js
_.sortedIndexBy(array, value, [iteratee=_.identity])
此方法类似于 _.sortedIndex
,只是它接受 iteratee
,后者为 value
和 array
的每个元素调用以计算它们的排序排名。迭代器使用一个参数调用:(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
array
(数组):要检查的排序数组。¥
array
(Array): The sorted array to inspect.value
(*):要评估的值。¥
value
()*: The value to evaluate.[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