Tell us what’s happening:
Have look in the test cases , im not understanding how the comparision in the
if condition takes place because we are using 2-d array in test cases but using only 1 for loop how can when i=0 check all three values in the array if it is not found or not(-1) .
Your code so far
function filteredArray(arr, elem) {
let newArr = [];
// Only change code below this line
for(let i=0;i<arr.length;i++){
if(arr[i].indexOf(elem) ==-1){
newArr.push(arr[i])
}
}
// Only change code above this line
return newArr;
}
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
Challenge: Iterate Through All an Array’s Items Using For Loops
If you write i.e. arr[0] you will get first element of the array arr. In this example that’s another array - [3, 2, 3]. So in condition indexOf() method is of the array is used to check whether elem is in arr[i], where i is from 0 up to length of the arr.