This function keeps returning error "Cannot read property 'length' of undefined" at line 4.
Why is arr[i] undefined?
function filteredArray(arr, elem) {
let newArr = []
for (i = 0; i <= arr.length; i++) {
for (j = 0; j <= arr[i].length; j++) {
if (arr[i][j] != elem) {
newArr.push(i)
}
}
}
return newArr
}
let result = (filteredArray([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9, 0]
], 3))
console.log(result)