0๐
โ
<% for(var i=1; i <= Object.keys(post).length ; i++) {%>
<%if(post['name' + i]){%>
<div class="name"><%- post['name' + i]%></div>
<% } %>
<% } %>
Try this, but you should definitely structure your post to be an array of objets so you can easily loop through it.
Source:stackexchange.com