Array with object sorting with Underscore sortBy

var sortedItem = _.sortBy(yourArrayName, ["start"])


I did it this way:

var sorted = _(list).sortBy(
                    function (item) {                        
                        return [new Date(item.effectiveDate).getTime(), item.batchId];
                    }), "batchId");

If you want it descending then it's the same thing but *-1

var sorted = _(list).sortBy(
                    function (item) {                        
                        return [new Date(item.effectiveDate).getTime()*-1, item.batchId];
                    }), "batchId");

In this example I am ordering by two fields, you can forget about the item.batchId.

Hope this helps someone.


Use an iterator function, not a single string for a property:

_.sortBy(arr, function(o) { return o.start.dateTime; })