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

288
Views
How to sort an array based on another array? (Javascript)

I have an array containing rows (tr elements) of a table:

var tbody = document.querySelector("#tasktable tbody");
var rows = [].slice.call(tbody.querySelectorAll("tr"));

Each of these rows has an input date element, in which I've stored each date value in an array and converted the date into a number (originally a string). Ex: "10-24-2021" --> 20211024.

I can easily sort the array of numeric date values in ascending order by:

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

However, I really just want to sort the rows in the table. How do I sort the row array based on the way the date array was sorted, since each date corresponds to the row by their index?

Thank you!

about 4 years ago · Juan Pablo Isaza
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!