how can i sort this tests array based on discount_price i have sorted only the lab_partners array,,,can anyone tell me how to sort the main array nd so that array should look something like : 200 ,250, 299 ,500 so my array is something like this - [ { [ ] } ,{ [ ] } , { [ ] } ,]
"tests": [
{
"id": 11,
"habit_test_id": 3,
"test_id": 1,
"test": {
"id": 1,
"test_name": "Blood Test",
},
"lab_partners": [
{
"id": 1,
"discounted_price": 250,
},
{
"id": 7,
"discounted_price": 299,
}
]
},
{
"test": {
"id": 4,
"test_name": "MRI",
},
"lab_partners": [
{
"id": 6,
"discounted_price": 500,
},
{
"id": 6,
"discounted_price": 200,
}
]
}
]
}
//this only sort the lab_partners array i want to sort on the basis of both test array
const condition_based= tests.map((itr, idx) =>
itr.lab_partners.sort((firstItem, secondItem) => ( firstItem.discounted_price -
secondItem.display_price)));
console.log(condition_based,'condition_based');
I don't really know what you are trying to achieve, or what you expect from this array, but please look into this
https://www.w3schools.com/JS/js_object_constructors.asp
It seems to me like there are some similarities in all the object values, and you are missing out some maybe just because they are null values.