I am trying to fetch all the costBreakdowns
where the canceled
status is false
. So I am trying to filter()
inside a filter()
to fetch the complete array except the ones where the costBreakdowns
have canceled
is true
:
const a = {
"activeBookingsCostBreakdownGroups": [{
"bookType": "RAIL",
"costBreakdowns": [{
"canceled": false,
"totalInTripCurrency": {
"amount": 43.39
}
}, ]
}, {
"bookType": "CAR",
"costBreakdowns": [{
"canceled": true,
"totalInTripCurrency": {
"amount": 86.78
}
},
{
"canceled": false,
"totalInTripCurrency": {
"amount": 87.79
}
},
]
}]
}
console.log(
a.activeBookingsCostBreakdownGroups.filter((elem) => (
elem.costBreakdowns.filter(el => el.canceled === false)
))
)
But it somehow returns all the elements as though the filter()
doesn't work.