To get max and min value from array in JavaScript, we the Math.max
and Math.min
methods.
For instance, we write
const array = [1, 3, 2];
const max = Math.max(...array);
const min = Math.min(...array);
to call Math.max
with the array
entries as arguments to return the max value from array
.
And we call Math.min
with the array
entries as arguments to return the min value from array
.
The spread operator spreads the array entries as arguments.