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)
Last active
May 21, 2024 15:15
-
-
Save onildoaguiar/6cf7dbf9e0f0b8684eb5b0977b40c5ad 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
God bless you chief!