Tell us what’s happening:
Describe your issue in detail here.
**Your code so far**
function filteredArray(arr, elem) {
let newArr = [...arr];
// Only change code below this line
for(let i=0;i<arr.length;i++)
{
for(let j=0;j<arr[i].length;j++){
if(arr[i][j]==elem)
{
newArr.splice(i,1);
}
}
}
// Only change code above this line
return newArr;
}
console.log(filteredArray([["trumpets", 2], ["flutes", 4], ["saxophones", 2]], 2) );```
**Your browser information:**
User Agent is: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0</code>
**Challenge:** Iterate Through All an Array's Items Using For Loops
**Link to the challenge:**
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-all-an-arrays-items-using-for-loops
We have defined a function, filteredArray , which takes arr , a nested array, and elem as arguments, and returns a new array. elem represents an element that may or may not be present on one or more of the arrays nested within arr . Modify the function, using a for loop, to return a filtered version of the passed array such that any array nested within arr containing elem has been removed.
it’s not the nested loops that’s the issue - it’s changing the array you are iterating on. splice changes the array, so the loop is jumping over some items