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

96
Views
¿Cómo agrupar la siguiente matriz y generarlos en ejs?

Esta es la matriz:

 const emails = [ { email: 'w@w', createdAt: 2022-03-31T17:07:36.675+00:00 }, { email: 'a@a', createdAt: 2022-03-31T17:07:36.675+00:00 }, { email: 'w@b', createdAt: 2022-04-31T17:07:36.675+00:00 }, { email: 'w@c', createdAt: 2022-04-31T17:07:36.675+00:00 }, { email: 'w@d', createdAt: 2022-06-31T17:07:36.675+00:00 }, ]

Quiero formatearlo así en ejs:

 <div class='card'> <h3>Unique Date</h3> <div class='emails'> <p>All the emails of that unique date</p> </div> </div>

¿Cómo puedo hacer eso?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En su back-end, querrá usar reduce y map para agrupar su matriz existente para hacer lo siguiente.

 // Group emails by date const groupedEmails = emails.reduce((acc, curr) => { const date = curr.createdAt.split('T')[0]; if (!acc[date]) { acc[date] = []; } acc[date].push(curr); return acc; }, {}); // Loop through grouped emails const groupedEmailsArray = Object.keys(groupedEmails).map(key => { return { date: key, // Sort emails by email in alphabetical order emails: groupedEmails[key].sort((a, b) => { if (a.email < b.email) { return -1; } if (a.email > b.email) { return 1; } return 0; }) } });

Luego querrá pasar groupedEmailArray a su vista y representar la vista de esta manera

 <div class='card'> <h3>Unique Date</h3> <div class='emails'> <p>All the emails of that unique date</p> <% for(let group of groupedEmailsArray) { %> <p> <%= group.date %> <% for(let item of group.emails) { %> <%= item.email %> <% } %> </p> <% } %> </div> </div>

Esto debería producir el resultado que está buscando.

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!