Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

270
Vistas
How to sort array of objects according to epoch time in JavaScript

I want to arrange the data which I am getting from the API according to the time. Here is one of the objects inside the array.

{
    "orderId": "xxxxxxxxxxxxx",
    "amount": 10,
    "status": "CREATED",
    "transactionTime": 1651498914,
    "type": "ADD",
    "mode": "UPI",
    "bankAccountId": {
        "bankAccountNumber": "xxxxxxxxxxxxx",
        "ifsc": "XXXX XXXX XXXX"
    }
}

I want to arrange the array in descending order according to the transactionTime which is an epoch time.

My initial approach.

data.map((item) => item.transactionTime)
   .sort()
   .reverse()
   .map((item) => {
        return data.find((i) => i.transactionTime == item);
})

This code is perfectly working but as you can see, it is not a good way to do this. So I want a more optimized solution. Someone suggested using a priority queue.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can directly subtract the times in the sort callback.

data.sort((a, b)=>b.transactionTime - a.transactionTime);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda