meanBy es-toolkit
Calculates the average of an array by applying the getValue function to each element.
Usage
meanBy(items, getValue)
Use meanBy when you want to find the average of the results of applying a function to each element of an array. It's useful for calculating the average of a specific property from an array of objects or for finding the average after transforming each element. If given an empty array, it returns NaN.
Parameters
An array to calculate the average.
A function that selects a numeric value from each element.
Returns
Returns the average of all values as determined by the getValue function. Returns NaN if the array is empty.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.