Last active
July 15, 2021 03:15
-
-
Save chris-burkhardt/1387cb658fd34d992169fc31fadb4115 to your computer and use it in GitHub Desktop.
NodeJS 12 sort() working
This file contains 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
var existingOrder = [{ | |
CreatedDate: "2021-07-12T03:49:57.000Z" | |
}, | |
{ | |
CreatedDate: "2021-07-13T09:25:23.000Z" | |
}, | |
{ | |
CreatedDate: "2021-07-18T04:52:41.000Z" | |
}, | |
{ | |
CreatedDate: "2021-07-14T05:27:32.000Z" | |
}, | |
{ | |
CreatedDate: "2021-07-10T08:18:57.000Z" | |
}, | |
{ | |
CreatedDate: "2021-07-14T08:19:42.000Z" | |
}, | |
{ | |
CreatedDate: "2021-07-16T08:37:15.000Z" | |
}, | |
] | |
existingOrder.sort((a, b) => { | |
const dateA = new Date(a.CreatedDate); | |
const dateB = new Date(b.CreatedDate); | |
return dateA > dateB ? -1 : 1; | |
}); | |
console.log(existingOrder); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment