Skip to content

minBy

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

此方法与 _.min 类似,不同之处在于它接受 iteratee,调用 array 中的每个元素生成值排序标准。迭代器使用一个参数调用:(value)。

¥This method is like _.min except that it accepts iteratee which is invoked for each element in array to generate the criterion by which the value is ranked. The iteratee is invoked with one argument: (value).

新增于

¥Since

4.0.0

参数

¥Arguments

  1. array (数组):要迭代的数组。

    ¥array (Array): The array to iterate over.

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

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

返回

¥Returns

(*):返回最小值。

¥()*: Returns the minimum value.

示例

¥Example

js
var objects = [{ 'n': 1 }, { 'n': 2 }];

_.minBy(objects, function(o) { return o.n; });
// => { 'n': 1 }

// The `_.property` iteratee shorthand.
_.minBy(objects, 'n');
// => { 'n': 1 }

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