Skip to content
Advertisement

Remove empty values from array of objects only if the value is empty in all objects

I’m trying to remove the empty strings in my array.

This is my array:

JavaScript

I would like to remove the empty string values ONLY if it’s empty in all objects.

desired outcome:

JavaScript

This is what I did but it removes EVERY empty string values:

JavaScript

Thanks in advance ,

Advertisement

Answer

If you don’t mind mutating the original array object. Here’s a solution utilizing some array functions.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement