Tell us what’s happening:
I need to remove all falsy values from an array. My code works except for the empty string… It still returns “” even when I wrote the if statement like this: if (arr[i] | arr[i] === “”)
I don’t understand why this happens. Shouldn’t an empty string return false?
thank you Your code so far
function bouncer(arr) {
let newArr = [];
for (let i = 0; i < arr.length; i++){
if (arr[i]);{
newArr.push(arr[i]);
}
}
return newArr;
}
console.log(bouncer([7, "ate", "", false, 9]));
console.log(bouncer([false, null, 0, NaN, undefined, ""]));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36.