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

188
Views
Ordenar una matriz de objetos que es el segundo elemento secundario de una matriz: por fecha y hora del objeto

¿Cómo puedo ordenar una [matriz de objetos por fecha] que es el segundo hijo de una matriz?

Obtengo la siguiente estructura de matriz:

 array = [ ["2022/04/14", [object]], ["2022/04/15", [object]], ["2022/04/20", [object, object, object]], ["2022/04/25", [object, object]], ["2022/04/30", [object]] ]; //where each object contain a date property that include time //for exemple each object get : { param1:"someText" date: Fri Apr 15 2022 18:00:00 GMT+0200 paramX:"someText" }

Para los días que incluyen más de un objeto, los objetos no se ordenan por hora.

He enviado un mensaje de texto con el siguiente método, pero no puedo tener éxito con él

 const sortedArray = array.sort((a, b) => { return new Date(a[1][1].date).getTime() - new Date(b[1][1].date).getTime(); });

¿Cómo puedo ordenar objetos por hora para cada día de esta matriz?

Gracias por tu ayuda

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Seguramente hay una forma más elegante de resolver este problema, pero aquí está mi enfoque.

 // Here is the result of sorting the objects const formattedArray = []; const sortedArray = array.forEach((item, index) => { const sortedObjects = item[1].sort((a, b) => { return new Date(a.date) - new Date(b.date); }); formattedArray[index] = [item[0], sortedObjects]; })

No necesita usar .getTime() .

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!