maxBy es-toolkit
Returns the element with the maximum value from the array based on the value returned by the transformation function.
Usage
maxBy(items, getValue)
Use maxBy when you want to transform elements in an array to numeric values using a transformation function and find the original element with the largest value. It returns undefined for an empty array.
It returns undefined for an empty array.
Parameters
The array to find the element with the maximum value.
A function that transforms each element into a number. It receives the element, its index, and the array.
Returns
The element with the largest value returned by the transformation function. Returns undefined if the array is empty.
Examples
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.