Categories
JavaScript Answers

How to use reduce() to find min and max values with JavaScript?

Spread the love

To use reduce() to find min and max values with JavaScript, we use the spread operator.

For instance, we write

const min = Math.min(...items);
const max = Math.max(...items);

to call Math.min with the values in the items array spread as arguments to get the min value in the items array.

And we call Math.max with the values in the items array spread as arguments to get the max value in the items array.

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 *