Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove All Falsy Values From An Array With Javascript
#1
This is another little snippet i wrote to Remove all falsy values from an array.
Falsy values in JavaScript are

false, null,  "", 0,  undefined,  and NaN.




Code:
function bouncer(arr) {
  var me = [];
  var ppp = NaN;
var err = [false, undefined, NaN, 0, null, ""];
  for(var i = 0; i < arr.length; i++) {
    if(arr[i] !== false && arr[i] !==null && arr[i] !==undefined & arr[i] !== "" && arr[i] !== 0) {
        me.push(arr[i]);
      
    }
    
  }
  var final = me.filter(function(me) {
        return Number.isNaN(me) === false;
      });
  return final;
}
bouncer([1, null, NaN, 2, undefined]);



If you have a simpler way of achieving this pls post it below.
It takes so long to learn simplicity.


Possibly Related Threads...
Thread Author Replies Views Last Post
  HELP: Pls What Are The Major Uses Of Javascript Broomboss 18 330 03-17-2018, 10:17 PM
Last Post: Broomboss
  TUTORIAL: Take A Selfie With Javascript SamBlingxZ 1 162 01-23-2018, 08:46 PM
Last Post: Broomboss
  How To Remove Google Gmail Account From Your Android Phone Without Factory Reset. Sesgist 0 61 12-21-2017, 10:47 AM
Last Post: Sesgist
  SHARED: Introducing Hbot.js Javascript Ai Library Horlahcoded 3 225 11-08-2017, 10:13 AM
Last Post: Horlahcoded
  SHARED: Introducing Hrouter.js Javascript Routing Library Horlahcoded 7 167 10-16-2017, 10:13 PM
Last Post: iamdannyfc
  SHARED: Introducing Hkwest.js Javascript Ajax Library Horlahcoded 0 96 10-15-2017, 09:46 AM
Last Post: Horlahcoded
  HELP: Javascript Vs Jquery. beme 10 398 08-21-2017, 07:20 AM
Last Post: beme
  Test Your Javascript Knowledge dealwap 10 631 08-16-2017, 07:41 PM
Last Post: Thepreditor
  How Can I Submit A Form Using Javascript iamdannyfc 11 311 06-22-2017, 10:13 PM
Last Post: bfaschat
  3 Types Of Javascript Animations That I So Much Admire! Laive 5 273 05-20-2017, 09:40 AM
Last Post: Laive



Users browsing this thread: 1 Guest(s)

About Nigeria's Creative Talents

Nigeria's Creative Talents is an online community where every creative Nigerians can share ideas with themselves.

For any more information, please use our contact form.

              User Links

              Advertise