Iterate through an array using loop

Hi guys, I’ve been stuck on this, tried using splice as well couldn’t manage for it to work, any tips for me :slight_smile: appericated , thanks.

  **Your code so far**

function filteredArray(arr, elem) {
let newArr = [];
// Only change code below this line
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
  if (arr[i][j] === elem) {
// 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: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36</code>

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

**Link to the challenge:**

Please take a look at the example code - it’s using neither .shift() nor .splice() but something else :wink:
Also consider taking a look at something like this JavaScript Array shift() Method to see what a method does, before you use it.

@TheOctagon3323 consider researching the indexOf() and combine it with the push() of Array

1 Like

thanks this advice was helpful :slight_smile:

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