I have an array MyArrayOfItems
of Item
objects with objects that look like this:
Item
{
ContainerID: i, // int
ContainerName: 'SomeName', // string
ItemID: j, // int
ItemName: 'SomeOtherName' // string
}
I want to sort this array so that it's sorted by ContainerID
and then by ItemName
alphabetically.
I have a custom sort function that so far looks like this:
function CustomSort(a, b) {
Item1 = a['ContainerID'];
Item2 = b['ContainerID'];
return Item1 - Item2;
}
MyArrayOfItems.sort(CustomSort);
This sorts by ContainerID but how do I then sort by ItemName?
Thanks.