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);