When using forEach in the include file, no parameters are defined.
Why is the error resolved when I use "if"?
main.ejs
<% const mainList = [
{
term: 'title1',
description: 'text1'
},
{
term: 'title2',
description: 'text2'
}
] %>
<%- include('./sub', { mainList: mainList }) %>
sub.ejs
<% mainList.forEach((item) => { %>
<dl>
<dt><%= item.term %></dt>
<dd><%= item.description %></dd>
</dl>
<% }) %>
Why is the error resolved?
<% if (typeof mainList !== 'undefined') { %> // Why is the error resolved?
<% mainList.forEach((item) => { %>
<dl>
<dt><%= item.term %></dt>
<dd><%= item.description %></dd>
</dl>
<% }) %>
<% } %>