30 seconds of code

  Back to Home

compact

arraybeginner

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);