The code is not working as accepted

Tell us what’s happening:
I thought this will remove all falsy value from the array but it is only removing the first found falsy element not the rest after that.

Your code so far


function bouncer(arr) {
for(let i=0;i<arr.length;i++){
  if(!arr[i]){
    arr.splice(i,1);
  }
}
console.log(arr)
return arr;
}

bouncer([7, "ate", "", false, 9]);

Your browser information:

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

Challenge: Falsy Bouncer

Link to the challenge:

changing the array you are iterating over is a really bad idea, and it causes unexpected effects, like you are experiencing

2 Likes

thanks! It was really silly but now I am ready to go :slightly_smiling_face: