Мне нужна помощь, мне нужно отсортировать массив по полю PendingQuantity.У меня есть отрицательные и положительные числа.Итак, мой код:
this.data.Products.sort(obj => obj.PendingQuantity);
Итак, мой массив
"Products": [
{
"ProductCode": "MC30180",
"Description": "Description_1",
"NationalCode": "N.C. 0965",
"PendingQuantity": 20,
"toBeScanned": true
},
{
"ProductCode": "Name_2",
"Description": "Description_2",
"NationalCode": "N.C. 0382",
"PendingQuantity": -3,
"toBeScanned": false
},
{
"ProductCode": "Name_3",
"Description": "Description_3",
"NationalCode": "N.C. 8913",
"PendingQuantity": 25,
"toBeScanned": false
}
]
порядок, который я хочу:
"Products": [
{
"ProductCode": "MC30180",
"Description": "Description_1",
"NationalCode": "N.C. 0965",
"PendingQuantity": -3,
"toBeScanned": true
},
{
"ProductCode": "Name_2",
"Description": "Description_2",
"NationalCode": "N.C. 0382",
"PendingQuantity": 25,
"toBeScanned": false
},
{
"ProductCode": "Name_3",
"Description": "Description_3",
"NationalCode": "N.C. 8913",
"PendingQuantity": 20,
"toBeScanned": false
}
]