Get maximum values of a multidimensional array with reduce function - Javascript Array Operation

Javascript examples for Array Operation:Array Search

Description

Get maximum values of a multidimensional array with reduce function

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(){/*from   w  w w  . j  a va2  s.  c o  m*/
var arr = [[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]];
var out = arr.reduce(function (p, c) {
  return p.concat(Math.max.apply(null, c));
}, []);
console.log(out)
    }

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

Related Tutorials