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

160
Views
Ordene los datos json según la fecha usando javascript
let array=[ { "id": "a572963a1bcd0550c4cf8518624bcb92", "type": "car", "created": "2022-01-18 12:47:08" }, { "id": "b84eb0fe1bc10550c4cf8518624bcb59", "type": "car", "created": "2022-01-18 06:23:39" }, { "id": "a95b65fc1b898110c4cf8518624bcbee", "type": "bike", "created": "2022-01-12 04:30:16" }, { "id": "5963929c1b018dd0c4cf8518624bcbc9", "type": "bike", "created": "2022-01-10 18:08:19" }, { "id": "515b65fc1b898110c4cf8518624bcb91", "type": "bus", "created": "2022-01-12 04:30:16" }, { "id": "7863929c1b018dd0c4cf8518624bcb52", "type": "bus", "created": "2022-01-10 18:08:17" } ]

Quiero ordenar los datos de la matriz JSON anterior en función de la fecha que está disponible en JSON tal como se creó. Elija solo los últimos datos creados.

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

0

array.sort((a,b) => a.created > b.created ? 1 : -1)

Esto debería funcionar si la cadena de fecha creada tiene el mismo formato

about 4 years ago · Juan Pablo Isaza Report

0

Para ordenar elementos por propiedad de fecha: Crédito

 array.sort(function(a,b){ // Turn your strings into dates, and then subtract them // to get a value that is either negative, positive, or zero. return new Date(b.date) - new Date(a.date); });

después:

 array.shift();
about 4 years ago · Juan Pablo Isaza Report

0

Puede usar la función de clasificación para ordenar según el valor de la fecha. Un código de línea se verá así

 let sortedArray = array.sort((a, b)=> (new Date(b.created) - new Date(a.created)));
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!