Created
June 28, 2021 20:41
-
-
Save DoctorDerek/e57ee1326bd4a77eff8cda0def2d9670 to your computer and use it in GitHub Desktop.
This one-liner uses the Boolean constructor to magically remove all falsy values from an array ✨ https://medium.com/p/87b5112f9f6d
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
console.log([undefined,"👋",null,"","🌎",0].filter(Boolean)) // ["👋","🌎"] | |
console.log(["👋",0,"🌎"].filter((item)=>Boolean(item))) // ["👋","🌎"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment