I have the following data structure:
[
{
"performanceDatetime": "2020-01-28T08:00:00Z",
"waivers": [
{
"ticketId": "66288",
},
]
},
{
"performanceDatetime": "2020-01-28T08:30:00Z",
"waivers": [
{
"ticketId": "63152",
},
{
"ticketId": "66113",
}
]
},
{
"performanceDatetime": "2020-01-28T09:00:00Z",
"waivers": [
{
"ticketId": "62667",
},
]
}
]
i.e., a list of objects. Inside these objects, there is another list: waivers. My question is, how would I filter the list waivers inside the list of objects, such that, if I filtered by, e.g., a ticketID of 63152, I'd receive the following returned:
[
{
"performanceDatetime": "2020-01-28T08:30:00Z",
"waivers": [
{
"ticketId": "63152",
}
]
}
]
Assuming the original data structure is stored as this.activeSurfersWaivers, I have tried the following:
const todaysWaivers = this.activeSurfersWaivers.filter((surfersWaivers) => {
surfersWaivers.waivers.filter((surferWaiver) => {
return (surferWaiver.ticketId.indexOf(this.searchedTicketID) >= 0);
});
});
Which returns an empty array for a value of this.searchedTicketID of 63152. Any pro-tips on filtering this awkward data structure would be greatly appreciated!