//This function removes falsey values from an array
function filterFalseyValues(arr) {
return arr.filter(ele => ele);
}
console.log(filterFalseyValues([0, "ate", "", false, 9]));
I'm confused about why just "ele" works as a condition. I am simply returning the parameter, yet it successfully filters out any falsey arguments through the function. Why does this work? Also, I am puzzled by why the line cannot be written as:
return arr.filter(ele => ele===true)
My intention is to check if an element of the array is true and return it, but this approach doesn't yield the desired result. I'm struggling to comprehend why. I can grasp the concept if I were attempting to filter like (ele => ele>5).