I'm given a matrix, and for every index that has a value of 0, I have to make the index directly below it to 0 as well.
for(let i = 0; i < matrix.length; i++) {
for(let j = 0; j < matrix[i].length;j++) {
//figure out what rooms not 0
if(matrix[i][j] !== 0) {
goodRooms.push(matrix[i][j])
} else {
matrix[i + 1][j] = 0;
}
}
}
I keep getting the
TypeError: Cannot set property '0' of undefined
At the else statement, and i'm not sure why.
matrix[i+1]isundefinedandj =0, then you try to set the property (undefined)[0] to an undefined object/arraymatrix[i+1].