Skip to content

Function.minBy

github-actions[bot] edited this page Nov 18, 2026 · 13 revisions

umt / minBy

Function: minBy()

minBy<T, K>(array, selector): T | undefined

Defined in: Array/minBy.ts:10

Returns the element whose selected value is the smallest Values are compared with <, so the first element wins ties and a key that never compares as smaller (such as NaN) never replaces the current minimum.

Type Parameters

T

T

K

K

Parameters

array

T[]

The array to scan

selector

(value) => K

Function returning the value to compare

Returns

T | undefined

The element with the smallest selected value, or undefined for an empty array

Example

minBy([{ n: 2 }, { n: 1 }, { n: 1 }], (item) => item.n); // { n: 1 } (the second element)

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally