Skip to content

Instantly share code, notes, and snippets.

@ThinhPhan
Created August 12, 2024 07:58
Show Gist options
  • Save ThinhPhan/962ca0bbe343a19ddb5bd83dd8ac26b9 to your computer and use it in GitHub Desktop.
Save ThinhPhan/962ca0bbe343a19ddb5bd83dd8ac26b9 to your computer and use it in GitHub Desktop.
JS - Filters out all the falsy values
// Falsy values in JavaScript are values that are considered false when evaluated in a Boolean context.
// These include0, false, "" (an empty string), undefined, NaN, and null.
const arr = [0, 1, false, 2, "", 3, undefined, NaN, null]
const filterFalsy = (arr) => arr.filter(Boolean)
console.log(filterFalsy(arr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment