Please help! Basic Data Structures: Iterate Through All an Array's Items Using For Loops


I’ve been following the curriculum in order and taking very detailed notes along the way, since JavaScript is the most difficult thing I’ve had to learn! (I’ve got a law degree and a Masters, yet basic JavaScript is blowing my mind!).

Anyway, I’m trying to look through the forums to really get an understanding for how this challenge works and what is being asked, but this, like a couple of others, doesn’t appear to me to request anything specific! It clearly must however, as everyone appears to understand what’s being asked - here is the challenge following the example:

" 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."

and here is the code:

function filteredArray(arr, elem) {
let newArr = ;
// Only change code below this line

// Only change code above this line
return newArr;

console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));

I’ve had to look ahead at the hints and the answer, yet I still don’t understand it! I see somewhere in the forums that someone mentions its purpose is to remove the '3’s from the nested arrays, but in the challenge description, I don’t understand where it requests that? It requests a filtered version of the nested array, but I’ve no idea by what measure we’re supposed to be filtering it.

Does the ‘elem’ declaration mean ‘how many elements there are’, which is 3 in each array? Is it the number ‘3’ that is declared after the arrays? If so to either of these, how is it known that these are specifically the elements we must remove/filter?

If anyone could break this down into human English, I’d be sincerely grateful and may even return one of the finest jokes known to all as a thank you!

Challenge: Iterate Through All an Array’s Items Using For Loops

Link to the challenge:

This right here is the challenge task.
It may sound complicated, but it boils down to:

“remove any sub-array from the main array which contains the passed element”.

So, given a list of lists (or an array of arrays if you prefer), and an element, give me back that list without any inner list that contains the element.

So, ideally what we have to do is look into each sub-list and check if the given element is present, if so remove the sub-list entirely, otherwise keep it as it is.

Hope it’s clearer now.

1 Like


So simple to when you word it like that!

I think if we were able to hover over the paragraphs and a description like that popped up, it would make these tasks flow even smoother for beginners like me!

Thank you so much again and as promised, here is one of the finest jokes of all time:

How many tickles does it take to make an octopus laugh?


(Like tentacles! Ahh magnificent!)


It would seem we’re at a very similar point in the curriculum and I think learning how to do this for ourselves is the essential skill I’m learning here. You should see the amount of notes I’ve made and doddles with arrows going everywhere trying to figure some of these out :slight_smile:

Amen! The amount of notepads I’m filling up with all of this, I’m looking like a serious danger to the trees!

I’ve found what’s been working for me mostly has been colour coding things (My headings have their own colour, the code has its own colour, the description of why it works and another colour for highlighting the most important parts) and putting things into as simple English as possible in the descriptions. SUPER time consuming, but I think it’s working for the best!

Is there anything you’re doing that you think is helping you learn faster/better :)?

Very similar things to you by the sounds of it :slight_smile:

What I find most helpful on the challenges is to copy the code snippets into playcode or codepen and mess around with them. That way I can throw in a load of console.log statements and see what it’s doing at each step. That’s really helped me to break things down and figure out what’s going on.

Edit: I also feel like I’m going super slowly a lot of the time and having to go back over things, sometimes again and again, until it feels like it’s sinking in. And some days it feels like it’s not sinking in at all and never will. On those days I try to remind myself that it’s normal and that this is what learning feels like :slight_smile:

1 Like

one thing to remember is that you do not need to memorize anything - everything is a google search away

just focus on understanding

1 Like

Ooo, I’ll have to have a look at ‘playcode’, sounds like a great idea :smiley:

You’re right about that, it really does check your ego, JavaScript is crazy! But it will totally be worth it! What made you choose to do this and not Python since that’s what many of the forums/Youtubers seem to be leaning in the direction of?

I’m not sure whether FCC has a follow function, but it’d be great to follow your journey through learning to code too and maybe help each other out from time to time!

All hail lord Google!

I’m just doing what FCC tells me to… :wink:

I want to get into some sort of software development, web development seems like a good starting point and JavaScript seems pretty essential for web development. So here we are.

I don’t know that it does have a follow function but feel free to shoot me a message any time if there’s a problem you want to talk through. It would be good to have friends on this ridiculous journey :slight_smile:

1 Like