Skip to main content

min()

min(array): number | undefined

Computes the minimum value of array.

DEPRECATED

Use Math.min(...array) directly instead.


Parametersโ€‹

array: readonly number[]โ€‹

The array to iterate over.


Returns: number | undefinedโ€‹

The minimum value, or undefined if array is empty.


See Alsoโ€‹

Math.min() - MDN


Sinceโ€‹

2.0.0


Also known asโ€‹

min (Lodash, es-toolkit, Radashi, Ramda) ยท โŒ (Remeda, Effect, Modern Dash, Antfu)


Exampleโ€‹

// โŒ Deprecated approach
min([4, 2, 8, 6]); // => 2
min([]); // => undefined

// โœ… Recommended approach
Math.min(...[4, 2, 8, 6]); // => 2
Math.min(...[]); // => Infinity (handle empty case manually)

How it works?โ€‹

Computes the minimum value of array. Deprecated: Use Math.min(...array) directly.

Native Equivalentโ€‹

// โŒ min(arr)
// โœ… Math.min(...arr)

Use Casesโ€‹

Find minimum ๐Ÿ“Œโ€‹

Find smallest value.

Math.min(1, 5, 3);     // 1
Math.min(...numbers); // from array

Clamp maximumโ€‹

Ensure value is at most maximum.

const atMost = Math.min(value, maximum);