Tell us what’s happening:
I’ve figured out the solution to this problem using one for loop.
But my initial inclination was to use a nested for loop since I was dealing with nested arrays. I don’t understand why I get 3 outputs of the passing array in the console.
Your code so far
function filteredArray(arr, elem) {
let newArr = [];
for (let i = 0; i < arr.length; i++){
for (let k = 0; k < arr[i].length; k++){
if (arr[i].indexOf(elem) == -1){
newArr.push(arr[i])
}
}
}
return newArr;
}
// change code here to test different cases:
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-all-an-arrays-items-using-for-loops/