无法读取属性';forEach&x27;未定义node.js的名称
我在这段代码中遇到了一个.forEach()错误无法读取属性';forEach&x27;未定义node.js的名称,node.js,express,foreach,Node.js,Express,Foreach,我在这段代码中遇到了一个.forEach()错误 ```<% if(locals.isAuthenticated) { %> <section> <h4>Leave a comment</h4> <form method="POST" action="/landmarks/<%= landmark.id %>/comments"> <textarea name="content" id=
```<% if(locals.isAuthenticated) { %>
<section>
<h4>Leave a comment</h4>
<form method="POST" action="/landmarks/<%= landmark.id %>/comments">
<textarea name="content" id="content" placeholder="Comment"></textarea>
<button class="button">Leave a comment</button>
</form>
</section>
<% } %>
<section>
<h4>Comments</h4>
<% landmark.comments.forEach((comment) => { %>
<p><%= comment.content %></p>
<small><%= comment.createdBy.username %></small>
<small><%= comment.createdAt.toDateString() %></small>
<% if(locals.isAuthenticated && comment.belongsTo(user)) { %>
<form method="POST" action="/landmarks/<%= landmark.id %>/comments/<%= comment.id %>">
<input type="hidden" name="_method" value="DELETE">
<button class="btn">Delete Comment</button>
</form>
<% } %>
<% }) %>
</section>```
```
留言
留言
评论
{ %>
删除评论
```
我不确定为什么会发生这种情况,因为我相信这是forEach方法的正确语法错误消息是说
landmark。注释
未定义。您需要从查看该值开始,找出为什么在您认为应该定义它时它未定义。如果landmark.comments 是一个数组。如果您将错误文本添加到问题中会更好。