I am trying to sort an array. I am trying to sort by "itemCommodity". I need to sort by numbers only first and then numbers with letters last. For example:
1000 A120 B330 2020 J954 5000
Should be displayed as:
1000 2020 5000 A120 B330 J954
I hope someone can help me out with this. I have an example of what i was trying below but it does not work as expected.
var product_data = [{
"itemCommodity": "1000",
},
{
"itemCommodity": "B330",
},
{
"itemCommodity": "A120",
},
{
"itemCommodity": "J954",
},
{
"itemCommodity": "5000",
},
{
"itemCommodity": "2020",
}]
product_data.sort(function(a, b) {
return a.itemCommodity - b.itemCommodity;
});
Please note that itemCommodity is not the only object in the array. I have about 40 different objects, just trying to sort on itemCommodity.