Skip to content

Instantly share code, notes, and snippets.

@codfish
Last active August 29, 2015 14:21
Show Gist options
  • Save codfish/851cc392f4fffff09605 to your computer and use it in GitHub Desktop.
Save codfish/851cc392f4fffff09605 to your computer and use it in GitHub Desktop.
Quick way to filter/remove non-truthy (null, empty string, number 0, NaN, boolean false) values from an array in Javascript.
['false', '', false, true, '0', 0, null, NaN, 1, '1'].filter(Boolean);
// => ["false", true, "0", 1, "1"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment