DEV Community

loading...

Filter out `falsy` values

Mehul Lakhanpal
Full stack Developer | Micro-blogging on Web Development at codedrops.tech | Creator of File Ops, Note Box, GitHub Marker
Originally published at codedrops.tech ・1 min read
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.

Instagram ● Twitter ● Facebook

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

Discussion (1)

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