DEV Community

Mehul Lakhanpal
Mehul Lakhanpal

Posted on • Originally published at codedrops.tech

Filter out `falsy` values

const arr = ["hello", false, 0, "", 7, true, "0", [], {}, null];
const filteredValues = arr.filter(Boolean);

console.log(filteredValues); //  [ 'hello', 7, true, '0', [], {} ]
Enter fullscreen mode Exit fullscreen mode

Thanks for reading 💙

Follow @codedrops.tech for more.

InstagramTwitterFacebook

Micro-Learning ● Web Development ● Javascript ● MERN stack ● Javascript

codedrops.tech


Projects

Note Box - A chrome extension to add notes/todos based on URL

File Ops - A VS Code extension to easily tag/alias files & quick switch between files

Top comments (1)

Collapse
 
jonrandy profile image
Jon Randy 🎖️
arr.filter(x=>x)
Enter fullscreen mode Exit fullscreen mode