I use a json file of matches and live score like that:
[
{
"league": {
"id": 722,
"name": "Liga Premier Serie A",
"country": "Mexico",
"logo": "https://media.api-sports.io/football/leagues/722.png",
"flag": "https://media.api-sports.io/flags/mx.svg",
"season": 2023,
"round": "Group 2 - 19"
},
"teams": [
{
"home": {
"id": 17787,
"name": "Lobos ULMX",
"logo": "https://media.api-sports.io/football/teams/17787.png",
"winner": null
},
"away": {
"id": 15932,
"name": "Irapuato",
"logo": "https://media.api-sports.io/football/teams/15932.png",
"winner": null
}
},
{
"home": {
"id": 15937,
"name": "Reboceros La Piedad",
"logo": "https://media.api-sports.io/football/teams/15937.png",
"winner": false
},
"away": {
"id": 15936,
"name": "Pioneros de Cancún",
"logo": "https://media.api-sports.io/football/teams/15936.png",
"winner": true
}
},
{
"home": {
"id": 19905,
"name": "CDS Tampico Madero",
"logo": "https://media.api-sports.io/football/teams/19905.png",
"winner": true
},
"away": {
"id": 22045,
"name": "Petroleros de Salamanca",
"logo": "https://media.api-sports.io/football/teams/22045.png",
"winner": false
}
},
{
"home": {
"id": 17788,
"name": "Montañeses",
"logo": "https://media.api-sports.io/football/teams/17788.png",
"winner": true
},
"away": {
"id": 22043,
"name": "Aguacateros de Peribán",
"logo": "https://media.api-sports.io/football/teams/22043.png",
"winner": false
}
},
{
"home": {
"id": 15919,
"name": "Atlético Saltillo",
"logo": "https://media.api-sports.io/football/teams/15919.png",
"winner": null
},
"away": {
"id": 19909,
"name": "Mexicali FC",
"logo": "https://media.api-sports.io/football/teams/19909.png",
"winner": null
}
}
],
"goals": [
{
"home": 0,
"away": 0
},
{
"home": 1,
"away": 2
},
{
"home": 2,
"away": 1
},
{
"home": 3,
"away": 2
},
{
"home": 0,
"away": 0
}
],
"score": [
{
"halftime": {
"home": 0,
"away": 0
},
"fulltime": {
"home": 0,
"away": 0
},
"extratime": {
"home": null,
"away": null
},
"penalty": {
"home": null,
"away": null
}
},
{
"halftime": {
"home": 1,
"away": 1
},
"fulltime": {
"home": 1,
"away": 2
},
"extratime": {
"home": null,
"away": null
},
"penalty": {
"home": null,
"away": null
}
},
{
"halftime": {
"home": 1,
"away": 0
},
"fulltime": {
"home": 2,
"away": 1
},
"extratime": {
"home": null,
"away": null
},
"penalty": {
"home": null,
"away": null
}
},
{
"halftime": {
"home": 1,
"away": 1
},
"fulltime": {
"home": 3,
"away": 2
},
"extratime": {
"home": null,
"away": null
},
"penalty": {
"home": null,
"away": null
}
},
{
"halftime": {
"home": 0,
"away": 0
},
"fulltime": {
"home": 0,
"away": 0
},
"extratime": {
"home": null,
"away": null
},
"penalty": {
"home": null,
"away": null
}
}
],
"venue": [
{
"id": 1072,
"name": "Estadio Miguel Alemán Valdés",
"city": "Celaya"
},
{
"id": 11250,
"name": "Estadio Juan N. López",
"city": "La Piedad"
},
{
"id": 1086,
"name": "Estadio Tamaulipas",
"city": "Tampico y Ciudad Madero"
},
{
"id": null,
"name": "Estadio de la Sociedad Cuauhtemoc Moctezuma",
"city": "Orizaba"
},
{
"id": 11237,
"name": "Estadio Olímpico Francisco I. Madero",
"city": "Saltillo"
}
]
},
{
"league": {
"id": 872,
"name": "Liga Premier Serie B",
"country": "Mexico",
"logo": "https://media.api-sports.io/football/leagues/872.png",
"flag": "https://media.api-sports.io/flags/mx.svg",
"season": 2023,
....
]
I use map within another map to get data:
newData?.map((match, index) => (
.......
[match]?.map((d, index) => ( // when I use match.teams.map((... I get all element but only under "teams" but other elements as "goals" I get "undefined"
<h3>{d?.teams?.home?.name}</h3>
<div>{d?.goals?.home}</div>
))
.....
))
I tried to get data of different elements in json format but I get undefined or cannot read properties.
For example, if I use match.teams.map((d, index) I get all elements under teams but I can’t get data under goals or score.
When I do [match]?.map((d, index) => ( I can get any elements under teams or any other specific fields.
Any Idea?