Menu

gitpiper

compact javascript Code Snippet in 2024

arraybeginner

Last Updated: 11 March 2024

Removes falsy values from an array.

  • Use Array.prototype.filter() to filter out falsy values (false, null, 0, "", undefined, and NaN).
const compact = arr => arr.filter(Boolean);
compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34]); // [ 1, 2, 3, 'a', 's', 34 ]

javascript snippet similar to compact For You in March 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️