I ended up recreating this with my own vision of what it 'should' look like (and apologies for the poor styling).
My main additions are as follows.
- Getting a unique array of regions, since that is how we plan on segregating the array of items.
const uniqueRegions = [...new Set(bridgesListData.map(({region})=>region))].sort()
- Next, based on the region you are in, you can retrieve the relevant items:
const itemsByRegion = (array, region) => {
return bridgesListData.filter((item)=>item.region === region)
}
Simply pass the function expression the array and region in question and you will have the items you want.
- Although it needs some styling help, the table can be displayed using a couple of
forEach loops (I really don't like using a for loop because of how much additional complexities (vs benefits) it introduces.
let template = `<% uniqueRegions.forEach(region => {
%>
<h1><%= region %></h1>
<table>
<thead>
<tr>
<th style="border-bottom: solid 1px black;">Truss Type</th>
<th style="border-bottom: solid 1px black;">Location</th>
<th style="border-bottom: solid 1px black;">Year</th>
</tr>
<thead>
<tbody>
<% itemsByRegion(bridgesListData, region).forEach(item => {
%>
<tr>
<th><%= item.trussType %></th>
<th><%= item.nameLocation %></th>
<th><%= item.year %></th>
</tr> <%
}) %>
</tbody>
</table>
<%}) %>`;
I hope I understood your requirements here.