What’s the EJS for diff?

  ejs, javascript, json, koa

I use ejs to write the web page.
But when i use for will have something wrong code

  1. Use for of can work
  2. But use for loop will fail

I don’t know this different…

<% for(post of posts){ %>
  <div class="layout-card p-5 mb-5">
    <h3 class="h3"><%= post.Title %></h3>
    <div class="text-muted mb-3"><small>
      <i class="fas fa-calendar-alt mr-2"></i>
      Create <%= post.UpDate.getFullYear() %>-<%= post.UpDate.getMonth() %>-<%= post.UpDate.getDate() %>
    </small></div>
    <p class="description text-left text-overflow"><%= post.Description %></p>
  </div>
<% } %>
<% for(var i=0;i<=posts.length;i++ ){ %>
  <div class="layout-card p-5 mb-5">
    <h3 class="h3"><%= posts[i]["Title"] %> </h3>
  </div>
<% } %>

Source: Ask Javascript Questions

LEAVE A COMMENT