
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to find the minimum value of an array in JavaScript?
We can find the minimum value of an array using Math.min() and sort()
1) Math.min()
Math.min() function usually takes all the elements in an array and scrutinize each and every value to get the minimum value.It's methodology is discussed in the below example.
Example
<html> <body> <script> function minimum(value) { if (toString.call(value) !== "[object Array]") return false; return Math.min.apply(null, value); } document.write(minimum([6,39,55,1,44])); </script> </body> </html>
Output
1
2) sort()
Using sort() and compare functions we can write the elements in ascending or descending order, later on using length property we can find the minimum in the following way
Example
<html> <body> <input type ="button" onclick="myFunction()" value = "clickme"> <p id="min"></p> <script> var numbers = [6,39,55,1,44]; document.getElementById("min").innerHTML = numbers; function myFunction() { numbers.sort(function(a, b){return b - a}); document.getElementById("min").innerHTML = numbers; document.write(numbers[numbers.length-1]); } </script> </body> </html>
After running the program the out put will be shown as in the following image
Output
On clicking the click me button above the output would display as
1
- Related Articles
- Find indexes of multiple minimum value in an array in JavaScript
- How to find the maximum value of an array in JavaScript?
- Function that returns the minimum and maximum value of an array in JavaScript
- Find the closest value of an array in JavaScript
- Write a Golang program to find the element with the minimum value in an array
- Find the maximum possible value of the minimum value of modified array in C++
- How to find the length of an array in JavaScript?
- How to find maximum value in an array using spread operator in JavaScript?
- How to find inside an array of objects the object that holds the highest value in JavaScript?
- Return an array of all the indices of minimum elements in the array in JavaScript
- PHP program to find the minimum element in an array
- How to find minimum value in MongoDB?
- How to find the minimum and maximum element of an Array using STL in C++?
- How to modify an array value of a JSON object in JavaScript?
- How to add new value to an existing array in JavaScript?

Advertisements