Find the smallest number in array JavaScript | Different methods examples

There are several built-in ways to find the smallest number in Array JavaScript. Some methods are using the Math functions with the spread operator (…) and sorting the array numerically with .sort().

Different methods of finding the minimum JS Array:-

  • Math functions
    • Math.min() – spread operator (…)
    • Math.min.apply() – (Without the spread operator)
  • Using a for loop or .reduce()

Find the smallest number in array JavaScript Example

Let’s see all ways to do in HTML with examples code:

Math.min() – spread operator (…)

The tersest expressive code to find the minimum value is probably rest parameters:

Math.min.apply() – (Without the spread operator)

Rest parameters are essentially a convenient shorthand for Function.prototype.apply when you don’t need to change the function’s context:

Using a for loop or .reduce()

User case for Array.prototype.reduce:

Output: Result will be same for all examples because input array values are same.

Find the smallest number in array JavaScript

Source: https://stackoverflow.com/

Using a for loop

Output: 1

Do comment if you have any problem and suggestion on 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.