I have an array full of objects which need to be sorted, however I cannot seem to get this working. Normally I would just do a simple sort() method, which works fine for sorting on a single column, however in this case I need to sort by one column and then by a second.
To try make this easier to understand, let’s say I have an array of objects similar to this one:
{ Name: 'Alfred', Total: 4, Project: 'Foobar' }
Now in this example, how would I go about sorting an array of these objects first by Name, and then by Total? I considered doing something like this:
myArray = myArray.sort(function(a,b){return (a.Name + a.Total) > (b.Name + b.Total)});
However I am not sure what is the best method to approach this. Some suggestions would be appreciated.
Minified version: