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

363
Views
Matriz de JavaScript: ordenar objetos anidados por clave

Tengo el siguiente objeto anidado. Me gustaría recorrer cada elemento (latest.sentTime) y luego ordenar el objeto en sí por "sentTime". Para que el mensaje más reciente esté en la parte superior. ¿Cómo puedo conseguir esto?

En el siguiente ejemplo, "0" y "1" deben intercambiarse básicamente, ya que "1" tiene un "sentTime" más reciente.

ingrese la descripción de la imagen aquí

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

0

  • Usando Array#map , itere sobre la matriz para obtener latest.sentTime
  • Usando Array#sort y Date , ordene los elementos

 const arr = [ { latest: { sentTime: '2022-02-05T19:15:32.000Z' } }, { latest: { sentTime: '2022-02-06T22:12:00.000Z' } } ]; const sentTimes = arr .map(({ latest }) => latest.sentTime) .sort((a, b) => new Date(b) - new Date(a)); console.log(sentTimes);

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!