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