Categories
JavaScript Answers

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

Spread the love

Sometimes, we want to get max and min value from array in JavaScript.

In this article, we’ll look at how to get max and min value from array in JavaScript.

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

To get max and min value from array in JavaScript, we use some math methods.

For instance, we write

const array = [1, 3, 2];
const max = Math.max(...array);
const min = Math.min(...array);

to spread the entries of array as arguments of Math.max and Math.min.

max returns the max value in the list of arguments.

min returns the max value in the list of arguments.

Conclusion

To get max and min value from array in JavaScript, we use some math methods.

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 *