I have this array ob objects that I need to sort by their number
var products = [
{
name: 'Gift Box',
productNumber: '44',
SKU: 'ABCD'
},
{
name: 'Tabletop Game',
productNumber: '63',
SKU: 'DEFG'
},
{
name: 'Poker Deck',
productNumber: '25s',
SKU: 'HIJK'
},
{
name: 'Box of chocolates',
productNumber: '96p',
SKU: 'LMNO'
},
{
name: 'Box of Swiss chocolates',
productNumber: '96s',
SKU: 'PQRS'
},
{
name: 'Gift card',
productNumber: '81',
SKU: 'TUVW'
}];
As you can see, some of the productNumber
properties have a letter in them, and as such, I think is not going to be as easy as just doing a products.sort((a, b) => parseInt(b.productNumber) - parseInt(a.productNumber));
, so, how can I solve this?