Skip to content

Function: max() ​

ts
function max(values): number;

Returns the maximum value from an array of numbers. 返回数字数组中的最大值。

Parameters ​

ParameterTypeDescription
valuesnumber[]Array of numbers / 数字数组

Returns ​

number

The maximum value / 最大值

Throws ​

Error if array is empty / 如果数组为空则抛出错误

Example ​

typescript
max([1, 2, 3, 4, 5]) // => 5
max([-10, 0, 10]) // => 10
max([]) // throws Error

Since ​

1.0.0

Released under the MIT License.