blog post

Sometimes, however, you need to pick the smallest or the biggest number from an array. In this case it’s your responsibility to provide such min/max functions. Clever usage of apply allows you to use built-ins functions for some tasks that otherwise probably would have been written by looping over the array values. As an example here we are going to use Math.max/Math.min to find out the maximum/minimum value in an array.

Source Code

<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
  </head>
<body style="text-align:center;">
<h2>Min OR Max Get From Array</h2>



</body>
<script>

var minMath = function (arr) {
      return Math.min.apply(Math, arr);
    };
    var maxMath = function (arr) {
      return Math.max.apply(Math, arr);
    };

$(document).ready(function(){

var numbers=[1,2,3,4,5,6,7,8,9,10]

$("#min").html('<b>Min Number is </b>: '+minMath(numbers));
$("#max").html('<b>Max Number is: </b>'+maxMath(numbers));

});
</script>
<pre>var numbers=[1,2,3,4,5,6,7,8,9,10];</pre>
<div id="min"></div>
<div id="max"></div>

Max and Min value of array in JQuery
  • Share This Story


Pleas give your valuable comments to improve the contents.

about author

Atul kumar shukla


I'm Atul Kumar Shukla, working as a web developer.
Welcome to my Blog. This is my personal blog where i post my own questions and answers , articles about ASP.Net., SQL Server, HTML, CSS, Jquery and many more..

Visit Profile

Leave a comment

Name
E-mail
Url
Message

Get More Stuff
Subscribing to the TheOneblogs newsletter and get intersting stuff and updates to your email inbox.
Your Email

 

Style Switcher

Change Color

×! We use cookies to improve your user experience. More information