A much cleaner approach is to just use CSS. The below style will hide divs which are emtpy.
div:empty { display: none } Below code will hide the empty fields (including their labels) when the content is empty. This code will hide the email Heading with an empty value.
Javascript code
let empty = document.querySelectorAll('.row > div');
empty.forEach(function(element) {
if (element.textContent === '') {
element.previousElementSibling.style.display = 'none';
element.style.display = 'none';
}
}); HTML code
Address
Beverly Hills 90210
Phone:
+1 1 11111111
Email:

