0

I'm creating an Strapi API and want to display them on the frontend. I can do this already but I want to display them in the HTML ordered from closest to latest.

My API returns JSON like this:

"id": 1,
    "title": "SpaceX Falcon 9 Starlink Launch 23",
    "description": "A SpaceX Falcon 9 Rocket will depart from Canaveral Space Force Station, Florida and deploy approximately 60 satellites.",
    "launchdate": "2021-04-07T07:04:00.000Z",
    "tag": null,
    "youtubeWatchcode": "",
    "buttonText": "Watch Live",
    "gridposition": "mainhead",
    "backgroundImagePlacement": 100,
    "launchid": null,
    "published_at": "2021-03-31T10:14:17.761Z",
    "created_at": "2021-03-31T10:14:02.128Z",
    "updated_at": "2021-03-31T05:07:16.729Z",
...

Keep in mind the "id" is not in the order of which I like. How do I sort by the "launchdate" value

Lachlan Kemp
  • 55
  • 1
  • 7
  • 2
    Does this answer your question? [Sort array of objects by string property value](https://stackoverflow.com/questions/1129216/sort-array-of-objects-by-string-property-value) – panoskarajohn Mar 31 '21 at 06:07
  • You could directly get the sorted response in strapi using rest query "http://localhost:1337/articles?_sort=launchdate:desc". Kindly refer https://strapi.io/documentation/developer-docs/latest/developer-resources/content-api/content-api.html#sort – Anuj Divkar Apr 05 '21 at 12:20

0 Answers0