I am trying to sort an array with objects based on multiple attributes. I.e if the first attribute is the same between two objects a second attribute should be used to comap
Just return an array of properties you want to sort with:
ES6 Syntax
var sortedArray = _.sortBy(patients, patient => [patient[0].name, patient[1].roomNumber])
ES5 Syntax
var sortedArray = _.sortBy(patients, function(patient) {
return [patient[0].name, patient[1].roomNumber]
})
This does not have any side effects of converting a number to a string.