Skip to content

Instantly share code, notes, and snippets.

@fastmover
Created March 9, 2018 17:15
Show Gist options
  • Save fastmover/a8cf64c0c6aab751cadede05af79f4c5 to your computer and use it in GitHub Desktop.
Save fastmover/a8cf64c0c6aab751cadede05af79f4c5 to your computer and use it in GitHub Desktop.
Sort dates in an array using moment.js
const ordered = {};
selectedDays.sort((one, two) => {
let ts1 = moment(one.getTime()).unix();
let ts2 = moment(two.getTime()).unix();
if(ts1 < ts2)
return -1;
if(ts1 > ts2)
return 1;
return 0
}).forEach((key) => {
ordered[key] = selectedDays[key]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment