I have following data:
const data =
[{date: "2022-05-10 13:36:00", open: 155.535, low: 155.4, high: 155.67, close: 155.44},
{date: "2022-05-10 13:35:00", open: 155.23, low: 155.2102, high: 155.62, close: 155.53},
{date: "2022-05-10 13:34:00", open: 154.97, low: 154.96, high: 155.29, close: 155.22}];
I am using following code to sort the data by date (oldest to newest):
const data =
[{date: "2022-05-10 13:36:00", open: 155.535, low: 155.4, high: 155.67, close: 155.44},
{date: "2022-05-10 13:35:00", open: 155.23, low: 155.2102, high: 155.62, close: 155.53},
{date: "2022-05-10 13:34:00", open: 154.97, low: 154.96, high: 155.29, close: 155.22}];
console.log(Object.entries(data).sort((([, a], [, b]) => {
return new Date(a.date) - new Date(b.date)
})).map(i=>{ return i[1]}))
In chrome, it renders pretty well, but on safari, it will not work and will maintain the original order.
My question is what makes this difference and how to make the sort algorithem work in all broswer?
Thanks!
P.S. I do check this question, Chrome and Safari javascript .sort() method works differently, but the answers indicated that The sort is not necessarily stable
, but according to mdn now:
Since version 10 (or EcmaScript 2019), the specification dictates that Array.prototype.sort is stable.
What I am missing?