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

162
Views
show only one item with express/ejs/mongo

I've been trying to make a very simple ToDo list but when I want to show the description of the tasks, it displays all the descriptions, not only for that task itself. See the image, I want only one description by each task. Whats happening

I'm using a forEach loop but idk if I should create a new variable to receive only the description of tasks. What can I do to show only one item from description and that's refer to the task.

Here is the EJS file:

<% todo.forEach(function(task) { %>
    <div class="itens">
        <li>
            <a class="item" href="/edit/<%= task._id %>">
                <%= task.task %>
            </a>
            <a class="item del-btn" href="/delete/<%= task._id %>" onclick="return confirm('Deseja excluir?');">
                <img class="trash-icon" src="/images/trash.png" alt="">
            </a>
            <a class="item del-btn" href="/delete/<%= task._id %>" onclick="return confirm('Tarefa Concluida?');">
                <img class="trash-icon" src="/images/done.png" alt="">
            </a>
            <% todo.forEach(function(desc) { %>
                <p>
                    <%= desc.desc %>
                </p>
            <% }); %>
        </li>
    </div>
<% }); %>

Hey, I figure out what was the problem here. The second loop is what makes the description show duplicated and not only for the task. Just erase the second loop and changes the <%= desc.desc %> to <%= task.desc %> and will work fine!

over 4 years ago · Santiago Trujillo
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!