Javascript Data Type How to - Find highest value in each array in two dimensional array








Question

We would like to know how to find highest value in each array in two dimensional array.

Answer


<!DOCTYPE html>
<html>
<head>
<script
  src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
</head><!--from www . jav  a 2 s .c  o  m-->
<body>
  <div id="highest"></div>
  <script>
var obj = {
  a: [123, 234, 456, 789],
  b: [321, 654, 987],
  c: [963, 852, 741]
};
var max = [];
for (var i in obj) {
  max.push(Math.max.apply(0, obj[i]));
}
$('#highest').append('<div>'+ max.join('</div><div>') +'<div>');
</script>
</body>
</html>

The code above is rendered as follows: