Find Array Min and Max value in JavaScript


Find Array Min and Max value in JavaScript : There are many ways to find the min and max value in JavaScript Array. Here in this tutorial we are going to create function to get Min and Max value from javascript array. We will explain functions with example and demo.


How to Find Array Min and Max value in JavaScript

You can find the min and max value in javascript array as below –

JavaScript Array Get Minimum Value-

You can use the following function to get the minimum value from the javascript array as below –

Find Array Min and Max value in JavaScript Example

<script type="text/javascript">
function getMinVal(array){
    return Math.min.apply(Math,array);
}
</script>

Try it »

If you run the above example it will give you minimum value from array.

JavaScript Array Get Maximum Value-

You can use the following function to get the maximum value from the javascript array as below –

Find Array Min and Max value in JavaScript Example : Max Value

<script type="text/javascript">
function getMaxVal(array){
    return Math.max.apply(Math,array);
}
</script>

Try it »

If you run the above example it will give you the maximum value from the array.

You can use the above function frequently anywhere in javascript. This is the one of the optimal way to find the minimum and maximum value from an array in javascript.


Advertisements

Add Comment

📖 Read More