Kaan Karaca Kaan Karaca - 2 years ago 88
Javascript Question

How to get largest value in multi-dimensional array

function largestOfFour(arr) {
var max = 0;
var newArr = [];

for (var i = 0; i < arr.length; i++) {
for (var j = i; j < arr.length; j++) {
max = Math.max(max, arr[i][j]);
return newArr;

Here is my code. It works for me but I want to know is there any other sort way to do this?

Answer Source

Try this:

function largestOfFour(arr) {
  return arr.map(function(item){
    return Math.max.apply(null, item);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download