I'm trying to remove the entire sub-array from arr if any of the items equal to elem.
Here's the code
function filteredArray(arr, elem) {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
if (arr[i][j] === elem) {
arr.splice(i, 1);
}
}
}
return newArr = [...arr];
}
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
If I remove the condition in the IF statement, the error disappears. Why is the condition in the If statement causing the error?
I'm trying to understand why the error is coming up so that I will not repeat it again