Return Largest Numbers in Arrays - How does this work?

I couldn’t find the way to take first element from each array.
Any idea how it works?

    function largestOfFour(arr) {
      
      for (i = 0; i < arr.length; i++) {
        arr[i] = arr[i].sort(function(a,b){return b - a;});
        arr = arr.slice(0);
      }
      
      return arr;
    }

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
1 Like

Thank you! I will try it.

document.getElementById ('Id').innerHTML=arr [0];

You can make your function return arr [0]