I have an array of objects coming from an api that looks like this
[{"HomeTeam": "HOU"}, {"AwayTeam": "GB"}, {"HomeTeam": "DAL"}, {"AwayTeam": "TB"}]
I'm using map to map over the objects and get the team names to put them into react table like this.
const results = data.map((teams) => ({
"Teams": // I need both teams here
}))
How can I map over the array and get both HomeTeam and AwayTeam values into Teams values?
I need the final object to look like this
[{"Teams": "HOU"}, {"Teams": "GB"}, {"Teams": "DAL"}, {"Teams": "TB"}]
data.flatMap(Object.entries)then work with the tuplesconst results = data.map(team => ({ Teams: team.HomeTeam || team.AwayTeam }));{ team: Name, type: HomeTeam/AwayTeam }or return a match object like so:{ HomeTeam: Name, AwayTeam: Name }