How to find minimum value in array using JavaScript

I have been using some JavaScript techniques in the past to find the minimum number in an array. I recently stumbled upon a real fast and simple solution to find the min number in an array and thought of sharing it with all of you. Let me know what do you think of this method.

var array =  [ "17", "15", "21", "5", "25", "10", "20" ];
var minvalue  = Math.min.apply(null, array);
console.log(minvalue);			

Output

5

Another Example

var array =  [10,3,2,5,9,20];
var minvalue  = Math.min.apply(null, array);
console.log(minvalue);	

Output

2

Leave a Reply

Your email address will not be published. Required fields are marked *