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

78
Views
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 answers
Answer question

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 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!