Get the Lowest Value of an Array in JavaScript
Get the lowest value of an Array
To get the lowest value of an array, we can use the built-in Math.min() method by passing the array of elements as a argument to it.So, It returns the lowest value from the given array.
Here is an example:
const arr = [2, 4, 1, 55, 34, 12];
const lowestValue = Math.min(...arr);
console.log(lowestValue);
Output:
1
In the example above, we have used the Math.min(..arr)
to get the lowest value of an array.
The Math.min() method accepts only the individual values but not an array, so we unpacked the array by using the es6 (…) spread operator and passed to it.
We can also call Math.min() method without unpacking the array by using the Function.prototype.appl() method.
Here is an example:
const arr = [2, 4, 1, 55, 34, 12];
const lowestValue = Math.min.apply(null, arr);
console.log(lowestValue);