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

80
Visualizações
Button on click not triggering my function

I have this project in which I have to sort all the Id and time with a respective button for each of them.

    {
      Id: 1,
      Time: "2022-01-18T14:52:48Z",
    },
    {
      Id: 3,
     Time: "2022-01-18T15:05:28Z",
    },
    {
      Id: 2,
      Time: "2022-01-18T16:57:58Z",
    },
    {
      Id: 0,
     Time: "2022-01-18T16:00:28Z",
    },
  ];

This is the sorting function that I came up with :

    data.sort(function(a, b) {
        return a.Id - b.Id;
      });
    
    data.sort(function(a, b) {
        return a.Time - b.Time;
    });

The problems that I am having is that my button on Click does not trigger data.sort function and I am not able to sort Id and Time at the same time. Any idea?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To trigger any function by clicking in javascript you have to make your function, like:

const dataSorting = () => {

    data.sort(function(a, b) {
      return a.Id - b.Id;
    });

}

And then assign it to your button, for example using addEventListener MDN Refrence

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