I am struggling to extract a specific value from a nested array within an array.
Here is an example structure of my array:
[
{
ConcessionId: 1,
ConcessionName: "Coyotes",
KnownAs: [
{
TeamId: 1,
Name: "Arizona Coyotes",
},
{
TeamId: 2,
Name: "Phoenix Coyotes",
}
]
},
{
ConcessionId: 2,
ConcessionName: "Devils",
KnownAs: [
{
TeamId: 3,
Name: "Colorado Rockies",
},
{
TeamId: 4,
Name: "New-Jersey Devils",
}
]
}
]
I need help with writing a function that will return the team name based on a provided parameter. For instance, if the parameter value is 3, I expect the function to return "Colorado Rockies":
public getInfo(_TeamID) {
const concession: ConcessionInfo[] = this.concessionList$.filter(function (x) {
x.KnownAs.filter( (y)=> {
y.TeamId= +_TeamID;
return y.Name;
})
})
}
I have tried using filters in various ways but couldn't achieve the desired result. It seems like there should be a more efficient way than using nested loops.
Any suggestions would be greatly appreciated. Thank you!