Last active
April 15, 2023 22:54
-
-
Save zmts/ea23aee5b499c6e6693fd9959bd159fb to your computer and use it in GitHub Desktop.
Sort by Date (underscore.js, moment.js)
This file contains hidden or 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 list = [ | |
| {DateFrom: '08/11/2016 10:00:00 PM'}, | |
| {DateFrom: '11/11/2014 10:00:00 PM'}, | |
| {DateFrom: '30/11/2016 10:00:00 PM'}, | |
| {DateFrom: '05/01/2015 10:00:00 PM'} | |
| ]; | |
| var sorted = _.sortBy(list, function(item){ | |
| return - moment(item.DateFrom, 'DD/MM/YYYY mm:hh:ss A').unix(); // parse date with moment >> format to UNIX timestamp | |
| }); | |
| console.log(sorted) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Зачем использовать lodash/underscore ради того, что уже очень давно есть в JS? Почему не так?