If you are a NodeJs developer who likes to take things in your own hands rather than relying on third-party libraries specifically lodash given the context, please read along.
Lodash is a great library with a lot of tricks down its sleeves but comes with an overhead cost. So why not use our EcmaScript knowledge to use without importing unnecessary cost to our code.
problem: remove falsy values from an array
const array = [1,2,"",3,null,undefined,4,false]
lodash solution :
_.compact(array);
ES solution :
array.filter(Boolean)
Here the Boolean constructor will take care of all the falsy values.
Top comments (0)