Basic Data Structures Question 11/20 Iterate Through Elements on an Array Using a For Loop I was trying to solve this problem using two for loops instead of using indexOf method suggested in the solution. My idea was to create a variable in which i would store all elements of arr[i] item that are not equal to elem, then if the length of that variable was the same as the length of the arr[i] (which it should be if there are no items that equal elem) i would push it to newArr but for some reason the code isn’t working.
function filteredArray(arr, elem) {
let newArr = [];
// Only change code below this line
for(let i=0; i<arr.lenght; i++){
let placeholder = [];
for(let j=0; j<arr[i].length; j++){
if(arr[i][j]!==elem){
placeholder.push(arr[i][j]);
}
}
if(placeholder.length===arr[i].length){
newArr.push(placeholder);
}
}
// Only change code above this line
return newArr;
}
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));