Facebook
From David Umansky, 3 Years ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 60
  1. function removeFalsy(arr) {
  2.    var indexNum;
  3.    for (item of arr) {
  4.         if (item === null || item === 0 || item === "" || item === false || item === undefined || item === NaN) {
  5.             indexNum = arr.indexOf(item);
  6.             arr.splice(indexNum,1)
  7.         }        
  8.     }
  9.     return arr;
  10. }
  11.  
  12. console.log(removeFalsy([NaN, 0, 15, false, -22, "", undefined, 47, null]));
  13.