Skip to content

Instantly share code, notes, and snippets.

@Subilan
Created November 15, 2019 16:28
Show Gist options
  • Save Subilan/b4933353086bb9dc9d884b77516aee4a to your computer and use it in GitHub Desktop.
Save Subilan/b4933353086bb9dc9d884b77516aee4a to your computer and use it in GitHub Desktop.
依据日期先后顺序排序
let array = [{id: 2, date: "2019/1/28"}, {id: 3, date: "2019/1/1"}, {id: 1, date: "2019/7/19"}];
array.sort(function(a,b){
return new Date(b.date) - new Date(a.date);
});
// Output
// [{id: 1, date: "2019/7/19"}, {id: 2, date: "2019/1/28"}, {id: 3, date: "2019/1/1"}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment