# lodash meanBy

类似 _.mean,除了它接受迭代函数来调用数组中的每一个元素,来生成其值排序的标准。

概要

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

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

添加版本

4.7.0

参数

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

返回 (number): 返回平均值。

例子


var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
 
_.meanBy(objects, function(o) { return o.n; });
// => 5
 
// The `_.property` iteratee shorthand.
_.meanBy(objects, 'n');
// => 5

Last Updated: 4/11/2023, 7:04:20 PM