0

Considering that I have the below response, which consists of date and time, I want them in sorted format. How can I sort the json of date time in descending format.

let data =

[
  {
    "created_at" : "2020-12-01T05:11:08Z",
    "id" : "1"
  },
  {
    "created_at" : "2022-10-10T06:18:08Z",
    "id" : "2"
  },
  {
    "created_at" : "2021-11-12T02:48:08Z",
    "id" : "3"
  },
  ,
  {
    "created_at" : "2021-11-12T02:49:08Z",
    "id" : "4"
  }
]

After applying the sorting code, I need the data should look like:

result =

[
  {
    "created_at" : "2022-10-10T06:18:08Z",
    "id" : "2"
  },
  {
    "created_at" : "2021-11-12T02:49:08Z",
    "id" : "4"
  },
  {
    "created_at" : "2021-11-12T02:48:08Z",
    "id" : "3"
  },
  {
    "created_at" : "2020-12-01T05:11:08Z",
    "id" : "1"
  }
  
]
VLAZ
  • 26,331
  • 9
  • 49
  • 67
Harry
  • 11
  • 3
  • The question has already been answered on other posts. https://stackoverflow.com/a/10124053/7670747 – Atul Stha Oct 28 '22 at 10:45
  • @AtulStha much easer when sorted lexicographically: https://stackoverflow.com/a/12192544 – VLAZ Oct 28 '22 at 10:45

0 Answers0