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