Get the minimum value in an array using JavaScript
Question:
How to get the minimum value in an array using JavaScript? Answer:
const myArray = [4, -14, 32, 7];
const minValue = Math.min(...myArray);
console.log(minValue ); // -14
Description:
In modern JavaScript getting the minimum value in an array is quite simple by using the Math.min
function and the spread ...
operator.
The static function Math.min()
returns the lowest-valued number passed into it, or NaN if any parameter isn't a number and can't be converted into one. The result is Infinity if no parameters are provided.
Reference:
Math.min reference
Share "How to get the minimum value in an array using JavaScript?"
Related snippets:
- Check if number is odd or even in JavaScript
- Round a number in JavaScript
- Get the absolute value of a number in JavaScript
- Generate random string in JavaScript
- Generate random date with JavaScript
- Generate a random number with fixed length using JavaScript
- Generate a random number in a range with JavaScript
- Get the minimum value in an array using JavaScript
- Get the maximum value in an array using JavaScript
- Convert a float number to integer in JavaScript
- Round a number to the nearest 10 using JavaScript
- Round down a number in JavaScript
- Round up a number in JavaScript
Tags:
min, minimum, lowest, value, array, get, find, javascript Technical term:
Get the minimum value in an array using JavaScript