Join Digital Nomads and Remote Workers to Ask Questions, Share Experiences, Find Remote Jobs and Seek Recommendations.

JavaScript: Find Minimum and Maximum value of an Array

Before the ES5, we use the Math.max.apply() and Math.max.apply() function to find the minimum or maximum value of an array. But since the spread operator is released, we recommend using the Math.min() and Math.max() with spread operator to accomplish this.

This is because it will reduce redundancy by simplify your syntax. It may makes your code looks much cleaner and better.

const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];

// Not Recommend
const min = Math.min.apply(null, numbers); 
const max = Math.max.apply(null, numbers); 

// Recommend
const min = Math.min(...numbers);
const max = Math.max(...numbers);

Further Readings

We Work From Anywhere

Find Remote Jobs, Ask Questions, Connect With Digital Nomads, and Live Your Best Location-Independent Life.