I tried using isNaN(value) and !isNaN(value) but I am unable to remove the NaN element in the give code without removing the strings. (Obviously because string is not a number).
function cleaner(arr) {
return = arr.filter(function f(value) {return (value !== false && value !== null && value !== 0 && value !== undefined)});
}
cleaner([7, "eight", false, null, 0, undefined, NaN, 9, ""]);
The above code should return [7, "eight", 9, ""];
falseandnullandundefinedare notNaNs. OnlyNaNisNaNNaNs.typeofof thevalueis either astringor anumberand you're done.