I am currently working on a function that loops through an array and eliminates any elements that are false, null, 0, undefined, NaN, or an empty string.
Instead of returning an empty array as expected, the current output is [null,0,null,null,""]
. Below is my code:
function bouncer(arr) {
for(i=0;i<arr.length;i++){
if(arr[i]===false||null||0||undefined||NaN||""){
arr.splice(i,1);
}
}
return arr;
}
bouncer([false, null, 0, NaN, undefined, ""]);
I need assistance in identifying what I am doing incorrectly and why the values are not being removed from the array.