Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

filter the falsy values out of an array in a very simple way!

var arr = [ 0, 1, '', undefined, false, 2, undefined, null, , 3, NaN ];
 
var filtered = arr.filter(Boolean);
console.log(filtered);
 
/*
    Output: [ 1, 2, 3 ]
*/
Source by www.techiedelight.com #
 
PREVIOUS NEXT
Tagged: #filter #falsy #values #array #simple
ADD COMMENT
Topic
Name
2+9 =