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

161
Views
ordenar HTMLCollection por fecha

Tengo una HTMLCollection de div que me gustaría ordenar por fecha y devuelve un error de que la ordenación en mi colección no es una función

 const date = new Date(); const stages = document.getElementsByClassName("cadre-affiches"); for (let i = 1; i < stages.length; i++) { stages[i].dateStage = new Date(stages[i].getAttribute("date")); if (stages[i].dateStage < date) { stages[i].remove(); } }; let sorted = stages.sort((a,b) => b.dateStage - a.dateStage); console.log(sorted);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

document.getElementsByClassName devuelve HTMLCollection que es un Object . Puede convertirlo en una Array para acceder a la función de sort .

Reemplace esta línea de código.

 let sorted = stages.sort((a,b) => b.dateStage - a.dateStage);

a esto

 let sorted = Array.from(stages).sort((a,b) => b.dateStage - a.dateStage);
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!