Is there a function available in underscore.js to sort an array of date in descending order?
Asked
Active
Viewed 1.2k times
2 Answers
5
A more complete answer has been asked on Stack Overflow before, fwiw. I think this is also a great answer to the question, provided by @Bergi :
It's the same answer as @Praveen's, but it includes an example detailing the property checking for date comparisons, i.e. if you're "time model" is {"start": {"dateTime": ...}, "end": {"dateTime": ...} }, then you can sort via:
_.sortBy(arr, function(o) { return o.start.dateTime; })
Thanks to @Praveen and @Bergi!

RoboBear
- 5,434
- 2
- 33
- 40
1
Splits a collection into sets, grouped by the result of running each value through iteratee. If iteratee is a string instead of a function, groups by the property named by iteratee on each of the values.
For sorting desc, you can reverse the array after sorting.

Praveen Prasannan
- 7,093
- 10
- 50
- 70