Skip to content

maxBy

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

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

¥This method is like _.max 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 maximum value.

示例

¥Example

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

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

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

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