Go Behind the Experience to see how Tecovas brings the West to life with Sanity 🤠 July 18th

Sorting a list with empty fields in descending order by date in JavaScript

2 replies
Last updated: Oct 25, 2021
Is there a way to order a list of items with descending order from a date field, but make the empty fields, with null value, come after the oldest date.
Oct 25, 2021, 3:21 PM
I ended up doing it in javascript
[
  ...filteredWork.filter((x) => x.date),
  ...filteredWork.filter((x) => !x.date),
]
Oct 25, 2021, 3:31 PM
Thanks! That looks a lot better
Oct 25, 2021, 4:44 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?