I am looking to refactor a section of code to organize and display my items by year without having to duplicate the code for each individual year. So far, I have attempted to loop through an array of years but have not been successful.
Below is the code snippet that I am currently duplicating in a 'view' file (ejs template) for 8 different years:
<ul><h3>YEAR 2017:</h3>
<% items.forEach(function(el){ %>
<% if(el.date.substring(7, 11) == "2017"){ %>
<li><%= el.date %>:
<% if(el.url){ %>
<a href="<%= el.url %>" title="<%= el.title %>"><%= el.title %></a>,
<% }else{ %>
<%= el.title %>,
<% } %>
<% if(el.by){ %>
<%= el.type %>, <%= el.by %>
<% }else{ %>
<%= el.type %>
<% } %>
@ <%= el.location %></li>
<% } %>
<% }); %>
</ul>