Looking for guidance on how to sort string dates in chronological order, any expert tips?
Let's say we have an array object like:
data = [
{id: "1", date: "18.08.2018"}
{id: "2", date: "05.01.2014"}
{id: "3", date: "01.01.2014"}
{id: "4", date: "20.05.2016"}
]
The desired outcome is: when the button is clicked, data should be returned in chronological order like:
data = [
{id: "3", date: "01.01.2014"}
{id: "2", date: "05.01.2014"}
{id: "4", date: "20.05.2016"}
{id: "1", date: "18.08.2018"}
]
I attempted sorting based on dates and months but not accounting for the year with this code:
data.sort(function(a,b){return b.date - a.date});