max()
max(
array):number|undefined
Computes the maximum value of array.
DEPRECATED
Use Math.max(...array) directly instead.
Parametersβ
array: readonly number[]β
The array to iterate over.
Returns: number | undefinedβ
The maximum value, or undefined if array is empty.
See Alsoβ
Sinceβ
2.0.0
Also known asβ
max (Lodash, es-toolkit, Radashi, Ramda) Β· β (Remeda, Effect, Modern Dash, Antfu)
Exampleβ
// β Deprecated approach
max([4, 2, 8, 6]); // => 8
max([]); // => undefined
// β
Recommended approach
Math.max(...[4, 2, 8, 6]); // => 8
Math.max(...[]); // => -Infinity (handle empty case manually)
How it works?β
Computes the maximum value of array.
Deprecated: Use Math.max(...array) directly.
Native Equivalentβ
// β max(arr)
// β
Math.max(...arr)
Use Casesβ
Find maximum πβ
Find largest value.
Math.max(1, 5, 3); // 5
Math.max(...numbers); // from array
Clamp minimumβ
Ensure value is at least minimum.
const atLeast = Math.max(value, minimum);