DEV Community

Discussion on: 1 line of code: How to clean an Array

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

Ah, I misread - you want to keep 0 and false. In which case, you can shorten to:

arr.filter(item => item || item === 0 || item === false)
Enter fullscreen mode Exit fullscreen mode

The !! is unnecessary.