# freeCodeCamp Challenge Guide: Iterate Through All an Array's Items Using For Loops

**URL:** <https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-iterate-through-all-an-arrays-items-using-for-loops/301161>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [August 3, 2019, 5:44am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-iterate-through-all-an-arrays-items-using-for-loops/301161 "2019-08-03T05:44:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [August 3, 2019, 5:44am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-iterate-through-all-an-arrays-items-using-for-loops/301161/1 "2019-08-03T05:44:34Z")

</div>

# [Iterate Through All an Array’s Items Using For Loops](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-all-an-arrays-items-using-for-loops)

* * *

## Hints

### Hint 1

- A `for` loop must be used to search through every element in the array.

```javascript
for (let i = 0; i < arr.length; i++) {}

```

### Hint 2

- Every element of the array must then be compared to the `elem` parameter passed through the `filteredArray()` function.

```javascript
if (arr[i].indexOf(elem) == -1) {
}

```

### Hint 3

- If a match is NOT found then `newArr` have that entire subarray added. The `push()` function is very useful here.

```javascript
newArr.push(arr[i]);

```

- Once that entire subarray is added to `newArr` the loop continue with the next element.

* * *

## Solutions

> **Solution 1 (Click to Show/Hide)**
>
> ```javascript
> function filteredArray(arr, elem) {
> let newArr = [];
> // change code below this line
> 
> for (let i = 0; i < arr.length; i++) {
> if (arr[i].indexOf(elem) == -1) {
> //Checks every parameter for the element and if is NOT there continues the code
> newArr.push(arr[i]); //Inserts the element of the array in the new filtered array
> }
> }
> 
> // change code above this line
> return newArr;
> }
> // change code here to test different cases:
> console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
> 
> ```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 8, 2025, 3:59pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-iterate-through-all-an-arrays-items-using-for-loops/301161/2 "2025-01-08T15:59:09Z")

</div>

Closed on January 8, 2025, 3:59pm UTC


