Basic Data Structures - Iterate Through All an Array's Items Using For Loops

Tell us what’s happening:
Describe your issue in detail here.

I have finished the challenge but I think I need more explanation to be clear

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])
      console.log(newArr)
    }
    
  }
  // Only change code above this line
  return newArr;
}

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 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

Challenge: Basic Data Structures - Iterate Through All an Array’s Items Using For Loops

Link to the challenge:

filteredArray gets 2 arguments, the first is an array of arrays. The second is the number that you want to filter. Then as you have and array of arrays arr[0] would be = [3,2,3] indexOf would look and check that in [3,2,3] there is a 3 then indexOf is distinct to -1. If there is no 3 indexOf returns -1 then that position of the array is pushed to the new array.
Basically your for loop go over the array, the only difference is that in a normal array arr[i] is a string or a number and here is an array

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.