πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

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?