I have an array of MyArrayOfItemsobjects Itemwith objects that look like this:
Item
{
ContainerID: i,
ContainerName: 'SomeName',
ItemID: j,
ItemName: 'SomeOtherName'
}
I want to sort this array so that it is sorted by ContainerID, and then by ItemNamealphabetically.
I have a custom sort function that still 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 sort by ItemName?
Thank.
source
share