min_by
statisticsFind minimum by a key function
Syntax
min_by(array, key) Parameters
array (array) The data to search
key (expression) The key to compare by
Returns
object The item with the minimum value for the key
Examples
Product with minimum price
Input:
min_by(.price) Output:
{"name": "Widget", "price": 9.99} Student with lowest score
Input:
min_by(.score) Output:
{"name": "John", "score": 45} The min_by() function finds the item in an array that has the minimum value for a specified key or expression.
Usage
Use min_by() to find the entire record/object that has the smallest value for a particular field, rather than just the minimum value itself.