min max values 2D array - Javascript Array Operation

Javascript examples for Array Operation:Associative Array

Description

min max values 2D array

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/* w w  w .j  av  a  2  s  .co  m*/
var x = [[11, 2, 31],[41, 5, 16],[7, 8, 9],[7, 8, 19]];
var min,max;
x.forEach(function(itm) {
  itm.forEach(function(itmInner) {
    min = (min == undefined || itmInner<min) ? itmInner : min;
    max = (max == undefined || itmInner>max) ? itmInner : max;
  });
});
console.log(max,min); 
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials