Thursday, January 9, 2020

goofy little filter shortcut

I needed to add a filter to ignore null data elements in a collection I wanted to render in react:
stuff.filter(thing=>!!thing)
worked but a coworker pointed out
stuff.filter(Boolean)
read a bit cleaner. (Though now that I think about it if the collection is large is it doing too much object creation?)

No comments:

Post a Comment