Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

How to find min/max value in array using JavaScript

by
Category:javascript
javascript
How to find min/max value in array using JavaScript

I have been using some JavaScript techniques in the past to find the maximum and minimum number in an array. I recently stumbled upon a real fast and simple solution to find the max and 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);
var maxvalue  = Math.max.apply(null, array);
console.log("minvalue= "+minvalue);			
console.log("maxvalue= "+maxvalue);	

Output

minvalue= 5
maxvalue= 25

Another Example

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

Output

minvalue= 2  
maxvalue= 20

0 Comments


Html code work in comment box


Related Post