Today I Learned

hashrocket A Hashrocket project

Filter empty strings from array

Given an array with many empty strings

arr = ["a", "", "b", "", "c", "", "d"];

To get rid of the empty strings call filter and pass the Boolean method.

arr.filter(Boolean);
> ["a", "b", "c", "d"]

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean

See More #javascript TILs
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.