DEV Community

Discussion on: 4 Helpful Javascript Array tricks you should know

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Better to do

[].filter(Boolean)
Enter fullscreen mode Exit fullscreen mode

As the Boolean constructor is called on falsey values and returns false to filter them.

Although the absolutely best way is to not allow falsey values into an array for processing, then no work is needed