Tell us what’s happening:
Describe your issue in detail here.
My code look legit but it dont working, i tired put in visualizer it cant detect false may i know why?
**Your code so far**
function bouncer(arr)
{
for (let i = 0; i < arr.length; i ++)
{
if(arr[i] === false || arr[i] === null || arr[i] === "" || arr[i] === undefined || arr[i] === NaN || arr[i] === 0)
{
arr.splice(i,1);
}
}
return arr;
}
bouncer([7, "ate", "", false, 9]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36
This lesson is trying to drive home that the condition in if statements is checking truthiness already. You do not need to check for every possible falsy value in JavaScript.
Second, splice mutates the array that you’re looping over. This is bad, because the loop termination depends on the i value and the array’s length, but the length keeps changing. A better approach is to do the opposite, build up a new array of values you want to keep, and return that new array at the end.