Doble for loop not needed?

Hello everybody,
working on the session ‘iterate through all array’s elements using a for loop’, this is my question: if the exercise was about sub-arrays in one array, plus the ‘elem’ item, why to iterate through them is not needed a double for loop??

for (let i=0;i<arr.length;i++){
if(arr[i].indexOf(elem)<0){
newArr.push(arr[i]);

Thanks so much for your time!!
Cheers!

Hey, can you clarify which exercise is this? Providing a link to that will be handy

1 Like

You used a double loop though :wink:
You didn’t “write” two loops, but what do you think .indexOf(elem) does? It loops over an array to find the index. So someone else has written the second loop, but you are using it, by calling the method.

Ok, so the first loop iterate through the array, while indexOf() iterate through elements within the sub-arrays?
Thanks so much, I got it now!! :pray:

That’s https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-all-an-arrays-items-using-for-loops

However, someone already replied my question!
Thanks!!