Remove Empty Strings from an Array in JavaScript and TypeScript
To remove empty strings from an array, filter them out: values.filter(Boolean) is the short version and values.filter(value => value !== “”) is the explicit one. Both return a new array and leave the original alone. If the array also contains strings that are only spaces or tabs, trim first: values.filter(value => value.trim() !== “”). The … Read more >>