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

Tell us what’s happening:
Describe your issue in detail here.
Yo my code doesn’t work, i believe that i figure out the theory but something is wrong with me
Your code so far

function filteredArray(arr, elem) {
  let newArr = [];
  // Only change code below this line
for (let i = 0; i < elem.length; i++) {
  if (arr[i].indexOf(elem) == -1) {
    newArr.push(arr[i]);
  }
}
  // Only change code above this line
  return newArr;
}

console.log(filteredArray([[10, 8, 3], [14, 6, 23], [3, 18, 6]], 18));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 OPR/91.0.4516.95

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

Link to the challenge:

what does this for loop say to do? (write out the explanation of this for loop in plain english for me)

Thank you. I realized that i write wrong that loop element

1 Like

first your answer is wrong, check the guide for this topic on the forum. basically you declared a new variable that is an array (newArr) you see it is empty. then you initialized the for loop (), and you go through every element in the array, where the array starts at index 0, and ends at the length of the array (i < arr.length), i++ is what the loop does each time is passes through the array it moves to the next element in the array. the if statement checks to see if elem is in arr, the part in the bracket is always truthy, and remember the indexof method will return -1 if that elem is not found, so that particular element is added to our own empty array newArr with push after each run. then we return newArr at the end.

please refer these links, and always try to read the documentation when you don’t understand a method