Categories
JavaScript Answers

How to get max and min value from array in JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *