Created
November 15, 2019 16:28
-
-
Save Subilan/b4933353086bb9dc9d884b77516aee4a to your computer and use it in GitHub Desktop.
依据日期先后顺序排序
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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