Remove all falsy values from an array.
Falsy values in JavaScript are false, null, 0, "", undefined, and NaN.
function bouncer(arr) {
var temarr =[];
for (let i=0;i<arr.length;i++)
{
if (Boolean(arr[i])==true)
{
temarr.push(arr[i]);
}
}
console.log(temarr);
return temarr;
}
bouncer([7, "ate", "", false, 9]);
Comments
Post a Comment