0

Find max and min of nested array of nested array like

var arry=[1,2,[14,56,34,[48,98]],[14,16,11,[18,81]],34,35]
Sooraj s
  • 17
  • 3
  • 8

1 Answers1

1

You could flat the array first and then take the wanted method with spreaded values.

const
    array = [1, 2, [14, 56, 34, [48, 98]], [14, 16, 11, [18, 81]], 34, 35],
    flat = array.flat(Infinity),
    min = Math.min(...flat),
    max = Math.max(...flat);

console.log(min, max);
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392