I have an array with objects that looks like this:
{
Title: "Title",
Url: "myUrl",
publishedDate: "19/01/2021"
},
{
Title: "Title 2",
Url: "myUrl",
publishedDate: "17/12/2020"
},
{
Title: "Title 3",
Url: "myUrl",
publishedDate: "11/03/2021"
},
{
Title: "Title 4",
Url: "myUrl",
publishedDate: "11/12/2020"
}
I have saved them in my state (array).
this.state.data
I want to order the objects based on the property "publishedDate" (and without using the new Date() due to memory efficiency). I try:
console.log(this.state.data.sort(function(a, b) {
var c = new Date(a.publishedDate);
var d = new Date(b.publishedDate);
return c.getTime() - d.getTime();
}))
But the objects are not in order. What is wrong in the code? Playground: