0 points

Remove false values from Javascript Array


dashboard

Fri Jan 17 2020 20:33:47 GMT+0000 (UTC)

Posted by @new_roman11 #javascript #arrays #jsfunctions

const compact = arr => arr.filter(Boolean);

compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34]); 
content_copy Copy

output will be: [ 1, 2, 3, 'a', 's', 34 ]