0

let a = [
  [1, 2, 3, [1, 233]],
  [33, 45, 65, 4, 111, 123],
  [34, 5, 6]
];

let max = a[0][1];
for (let i = 0; i < a.length; i++) {
  for (let j = 0; j < a[i].length; j++) {
    if (a[i][j] > max) {
      max = a[i][j];
      for (let k = 0; k < a[i][j].length; k++) {
        if (a[i][j][k] > max) {
          max = a[i][j][k];
        }
      }
    }
  }
}
console.log(max);
mplungjan
  • 169,008
  • 28
  • 173
  • 236

1 Answers1

3

You can flatten the array and use Math.max() to get the max.

> Math.max(...a.flat(Infinity))
233
Davo
  • 526
  • 3
  • 19