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.