get biggest array element based on his second sub array value - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

get biggest array element based on his second sub array value

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 a v  a2  s  .  c o m
var a = [[-76, 2], 
         [-73, 1], 
         [-72, 5], 
         [-71, 1], 
         [-79, 2], 
         [-78, 1], 
         [-75, 1], 
         [-74, 1], 
         [-73, 1], 
         [-71, 2], 
         [-79, 1], 
         [-77, 1], 
         [-76, 1], 
         [-73, 2], 
         [-70, 2]];
a.sort(function(a, b) {
    return b[1] - a[1];
});
console.log(a[0]);
    }

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

Related Tutorials