I have array of grouped by scheduledOn data as below
[{
scheduledOn: "2020-02-05T00:00:00"
matches:
{id: 1, homeTeamName: "BLUE", homeTeamId: 1, homeScore: 1, awayTeamName: "Red", awayTeamId: 2, …}
{id: 2,homeTeamName: "Red", homeTeamId: 2, homeScore: 1, awayTeamName: "Yellow", awayTeamId: 3, …}
},
{
scheduledOn: "2020-01-06T00:00:00"
matches:
0: {id:3, homeTeamName: "BLUE", homeTeamId: 1, homeScore: 0, awayTeamName: "Yellow", awayTeamId: 3, …}
}]
I would like to return one matches object(Not an array) that match with selected id
Possible Solution I tried 1:
matches.map(match => match.matches
.find(m => m.id === selectedId))
this returns:
[{
id: 1, homeTeamName: "BLUE", homeTeamId: 1, homeScore: 1, awayTeamName: "Red", awayTeamId: 2, …
}]
but I want this to be just an object instead of array.
Possible Solution I tried 2:
matches.map(match => match.matches
.filter(m => m.id === selectedId))
.map(match => console.log(match
)
this returns:
[
{id: 1, homeTeamName: "BLUE", homeTeamId: 1, homeScore: 1, awayTeamName: "Red", awayTeamId: 2, …}
]
But this also returns as array.
Is there a way that I can have matched id object instead of array?
Thanks for all your help