Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DoctorDerek/e57ee1326bd4a77eff8cda0def2d9670 to your computer and use it in GitHub Desktop.
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
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