const posts = [
{ slug: "third", date: new Date("2022-02-23") },
{ slug: "fourth", date: new Date("2022-01-10") },
{ slug: "first", date: new Date("2022-01-01") },
{ slug: "second", date: new Date("2022-01-05") },
]A new list of posts sorted by date can be created like this:
// Ascending order:
const asc = posts.sort((postA, postB) => postA.date.getTime() - postB.date.getTime())
// Descending order (latest post first):
const desc = posts.sort((postA, postB) => postB.date.getTime() - postA.date.getTime())