Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JailsonSousa/00db3854ee83b8525c9ff91c2a458319 to your computer and use it in GitHub Desktop.
Save JailsonSousa/00db3854ee83b8525c9ff91c2a458319 to your computer and use it in GitHub Desktop.
Sorting an array by date with Moment.js
const Moment = require('moment')
const array = [{date:"2018-05-11"},{date:"2018-05-12"},{date:"2018-05-10"}]
const sortedArray  = array.sort((a,b) => new Moment(a.date).format('YYYYMMDD') - new Moment(b.date).format('YYYYMMDD'))
console.log(sortedArray)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment