阅读(2912) (0)

Lodash _.minBy

2021-09-22 10:21:04 更新

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

这个方法类似_.min 除了它接受 iteratee 来调用 array中的每一个元素,来生成其值排序的标准。 iteratee 会调用1个参数: (value) 。

添加版本

4.0.0

参数

  1. array (Array): 要迭代的数组。
  2. [iteratee=_.identity] (Function): 调用每个元素的迭代函数。

返回

(*): 返回最小的值。

例子

var objects = [{ 'n': 1 }, { 'n': 2 }]; 
_.minBy(objects, function(o) { return o.n; });
// => { 'n': 1 } 
// The `_.property` iteratee shorthand.
_.minBy(objects, 'n');
// => { 'n': 1 }