const arr = [
{
name: 'a',
date: '2022-01-01'
},
{
name: 'b',
date: '2021-01-01'
}
]
arr.sort((a, b) => a.date.localeCompare(b.date));
or
arr.sort((a, b) => a.date > b.date? -1 : a.date < b.date? 1 : 0);
arr.sort((a, b) => b.date.localeCompare(a.date));
or
arr.sort((a, b) => a.date < b.date? -1 : a.date > b.date? 1 : 0);