JavaScript array min value | Example code

Use Math.min() function to get the minimum valued number passed into it, or NaN if any parameter isn’t a number and can’t be converted into one.

Buy functions min accept only number arguments. You have to use spread operator (…), apply() or reduce() with math.

JavaScript array min value Example

HTML example code:

Since Math.min() expect the numbers as arguments, and not an array.

Math.min() with spread operator (…)

These built-in Math functions, will work with array.


Calling the function Function.prototype.apply() will have the same effect as the spread syntax:

Sorting Array

The code sort((a,b) => a-b) will sort numbers in ascending order from smallest to largest.

Using a for loop or .reduce()

You can use for loop to find the minimum numbers in an array:

Using Reduce method

Output: Minimum value will be same for all example because Array have same values.

JavaScript array min value

Do comment if you have any doubts and suggestions in this JS Array topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.