Categories
JavaScript Answers

How to obtain smallest value from array in JavaScript?

Spread the love

Sometimes, we want to obtain smallest value from array in JavaScript.

In this article, we’ll look at how to obtain smallest value from array in JavaScript.

How to obtain smallest value from array in JavaScript?

To obtain smallest value from array in JavaScript, we can use the Math.min method.

For instance, we write

const arr = [14, 58, 20, 77, 55, 34, 25, 8];
const min = Math.min(...arr);
console.log(min);

to call Math.min with the arr array entries spread as arguments of Math.min to get the smallest number in arr.

Conclusion

To obtain smallest value from array in JavaScript, we can use the Math.min method.

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 *