I am trying to write a Javascript code that removes all the false values from a given array. The code works for the first negative value is finds and doesn't work on subsequent false values as if once the switch is run, the whole for loop is broken.
My code is below.
function bouncer(arr) {
for(var i=0;i<arr.length; i++){
switch(arr[i]){
case false:
case null:
case 0:
case "":
case undefined:
case NaN: arr.splice(i,1); break;
}
}
return arr;
}
bouncer([7, "ate", false,"", 9]);
Is this normal switch behaviour?