var filtered = []; for (var i = 0; i < all.length; i++) { if (document.getElementById(all[i]).offsetHeight) filtered.push(all[i]); } alert(filtered.join(','));