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)
Forked from onildoaguiar/sorting-an-array-by-date-with-moment-js.md
Created
May 19, 2020 08:22
-
-
Save JailsonSousa/00db3854ee83b8525c9ff91c2a458319 to your computer and use it in GitHub Desktop.
Sorting an array by date with Moment.js
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment