Skip to content

JavaScript - Remove Falsy Elements From an Array

Published: at 02:23 PM

I found this quite clever:

[1, 2, "b", 0, {}, "", NaN, 3, undefined, null, 5, true, false].filter(
  Boolean
) > [1, 2, "b", {}, 3, 5, true];