Array(6) [
"10-2022 - 12-2022",
"08-2022 - 09-2022",
"07-2023 - 10-2023",
"04-2022 - 07-2022",
"01-2023 - 06-2023",
"01-2022 - 03-2022" ]
I want to sort this array of date ranges to show the latest date range at the beginning of the array. Having some trouble because the dates are in string format.
Array.sortcan take acomparefunction as a parameter so you need to implement one which works with your input. Also, be aware thatArray.sortmutates the array, which will make you run into problems with React if you don't make a copy beforehand.Array.sortbut had no luck. I think its because it takes a range of dates as the argument ` "10-2022 - 12-2022"` .