Created
August 12, 2024 07:58
-
-
Save ThinhPhan/962ca0bbe343a19ddb5bd83dd8ac26b9 to your computer and use it in GitHub Desktop.
JS - Filters out all the falsy values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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