[Help]Iterate Through All an Arrays Items Using For Loops

Tell us what’s happening:
What’s wrong with this code? All conditions pass the test except one.

Your code so far

function filteredArray(arr, elem) {
  let newArr = [];
  let temp=0;
  // 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){
  // change code above this line
  return newArr;

// change code here to test different cases:
console.log(filteredArray[ ["trumpets", 2], ["flutes", 4], ["saxophones", 2] ], 2);

Your browser information:

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

Link to the challenge:

temp is never reset. I hope this hint might help you :slight_smile:

1 Like

Now I realized my silly mistake, Anyways thanks for your reply😊