DEV Community

Discussion on: 14 Awesome JavaScript Array Tips You Should Know About

Collapse
 
olvnikon profile image
Vladimir

Thank you for the nice tips!

How to Remove All Falsy Values From an Array

You can also use simple coercion to Boolean

const fruits = ["🍎", false, "🍌", undefined, "🍒"];

const filteredFruits = fruits.filter(Boolean);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
hilleer profile image
Daniel Hillmann

Was about to suggest this as well. Much cleaner to me :-)