0
你好朋友我有一个JavaScript数组,我想从最近到最近的日期排序它。排序功能不起作用我不知道我在做什么错...任何人都可以帮助我?提前谢谢了!日期排序javascript数组
[Object, Object, Object, Object, Object]
0 : Object
favoriteTimestamp : Object
date : "2016-09-30 10:45:13.000000"
timezone : "Europe/Brussels"
timezone_type : 3
这里是我的排序功能:
console.log(results);
let sortedResults = results.sort(function(a, b) {
a.favoriteTimestamp.date - b.favoriteTimestamp.date;
});
console.log(sortedResults);
两个日志给相同的输出,因此排序没有工作:“(
感谢所有帮助:)
相关:[用JavaScript比较两个日期](http://stackoverflow.com/questions/492994/compare-two-dates-with-javascript#493018)。 –
'(a,b)=>(new Date(b.favoriteTimestamp.date))。getTime() - (new Date(a.favoriteTimestamp.date))。getTime()' – Redu
@Redu我很抱歉,不明白你的答案,这是我必须在返回排序功能? –