# Math.max and Math.min Examples

## `Math.max`

The general syntax for this method is:

``````   Math.max(x, y, z, ...)
``````

This method finds and returns the largest value from a set of numbers (x, y, z, …).

To find the maximum value in an array, see below.

## `Math.min`

The general syntax for this method is:

``````   Math.min(x, y, z, ...)
``````

This method finds and returns the smallest value from a set of numbers (x, y, z,…).

To find the minimum value in an array, see below.

## Max and Min of an Array

Unfortunately, the `max` and `min` methods will NOT take an array of numbers as an argument. There are numerous workarounds. Here are TWO possible solutions.

### Sort First

This approach uses the syntax from the sorting studio to first order the array. The maximum (or minimum) value can then be identified with bracket notation.

An alternative to the sorting approach described above is to use the spread operator (`...`), also called spread syntax.
In cases where a set of numbers or strings (x, y, z, etc.) is expected, an array cannot be used as-is. The spread operator expands an array into a comma-separated set of elements, which can be passed as arguments in a function call. `functionName(...[x,y,z])` is identical to `functionName(x,y,z)`.
Note the absence of brackets, `[]`, around the numbers printed by line 6. `console.log(...numbers)` executes as `console.log(2, 3, 100.01, 0, -5.2, 100)`, so the output is NOT an array.