Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
How can I control where an item is placed in a dynamically rendered EJS list?

I have an <ol> in EJS that consists of info obtained from objects in a database. As I make new objects, the list gets a new <li> with their information. These objects all have a date as their first field.

Is it possible to have the <ol> sort itself chronologically based on this date field? i.e., nearest date is '1' in the list, but if an object with an earlier date is added it will become '1' and the previous near date becomes '2'. The date is also contained in its own <span> within the list.

Here's what my EJS is looking like for now:

    <ol class="shows">
    <% for(let i=0; i < info.length; i++) {%>
        <li class="show">
            <span class="bold"><%= info[i].date %></span><span>  </span><span><%= info[i].bands %></span><span> - </span><span><%= info[i].venue %></span><span> - </span><span><%= info[i].ticketPrice %></span><span> - </span><span><%= info[i].startTime %></span><span> - </span><span><a href="<%= info[i].ticketLink %>">♣</a></span>
        </li>
    <% } %>
    </ol>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simply sort your array...

info.sort((a,b)=> b-a)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!