for(var i=0;i<arr.length;i++){
d=arr[i][j]; // <------- THIS IS THE PROBLEM
for(j=0;j<arr[i].length-1;j++){
if(arr[i][j+1]>d){
d=arr[i][j+1];
}
}
arr2.push(d);
}
First time through, works fine. Because j = 0 before the loop begins, right? Sure. Now, at the SECOND time through, hitting the SECOND array, j is NOT zero, it’s the index of the last element of the FIRST array. And that happens every time.
In every case, you want the loop to start at its FIRST member, so using the variable j there adds a possible point where things could break. As a general rule, avoid referencing two variables of the same name in the same function scope (one in the function with a var, and one in inner loop with a let, but both with the same name and serving a similar purpose).