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

143
Visualizações
Api: sort id base on start dates and hours in javascript

I would like to sort dates according to each id and when an id is passed it will appear in a "passed id" section, if it is in progress in a "current" section and if it is not in progress passed in a "coming soon" section. Start and end have this format: start: '2021-04-26T13:00:00.000Z', end: '2021-04-26T15:30:00.000Z'

Thank you !

here is my code :

fetch(urlCourses)
  .then(res => res.json())
  .then(function (data) {

    let donnees = data;

    //console.log( JSON.stringify(tabStudents));
  donnees.forEach(e => {
      tabCourses.push({
        'id': e.id,
        'name': e.name,
        'start': e.start,
        'end': e.end,
        'school_id': e.school_id,
       
        //'students': e.STUDENTS,
        'classroom': e.classroom
      });
    });
   
    tabCourses.sort(function (a, b) {
      return new Date(a.start) - new Date(b.start);
    });
    
   console.log('tabCourses sorted', tabCourses);

  
  })
  .catch(function (error) {
    console.log(error);
  });
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If you want to sort by a column and then by another column, I can refer you to this answer. (the brilliant one) sort Javascript array by two numeric fields

Should you want to sort into 3 distinct lists according to the value of dates (start, end and current) then first you want to run over the array, adding a column named "section" with possible values of : "passed", "progress", "future".

Then you can sort by it or separate it into 3 lists.

I leave it to you or others to write the code for that.

about 4 years ago · Juan Pablo Isaza Relatório

0

Convert your date in timestamp and it will do the trick

    tabCourses.sort(function (a, b) {
  return new Date(a.start).getTime() - new Date(b.start).getTime();
});
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