I am using the example below to sort an array by key. This is sorting the categories in order.
product_data.sort(function(a, b) {
return a.itemCategory - b.itemCategory;
});
My question is how do I sort with other keys as well. I need to sort by itemCommodity, itemCategory, and itemName. The commodity and category needs to be in numerical order from low to high and the itemName needs to be alphabetical. I was trying this but i dont think its working correctly.
product_data.sort(function(a, b) {
return a.itemCategory - b.itemCategory || a.itemCommodity - b.itemCommodity || a.itemName - b.itemName;
});