Categories
JavaScript Answers

How to obtain smallest value from array in JavaScript?

Spread the love

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

For instance, we write

const arr = [14, 58, 20, 77, 66, 82, 42, 67, 42, 4];
const min = Math.min(...arr);

to call Math.min with the entries in the arr array as arguments to get the min number from the arr array and return it.

We use the spread operator to spread the arr values 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 *