Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
sort HTMLCollection by date

I have an HTMLCollection of div that i would like to sort by date and it return an error that the.sort on my collection is not a function

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 Respostas
Responde à pergunta

0

document.getElementsByClassName return HTMLCollection which is an Object. You can convert it to an Array to access the sort function.

Replace this line of code.

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

to this

let sorted = Array.from(stages).sort((a,b) => b.dateStage - a.dateStage);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda