0

I'm having trouble accessing an inner array (9th line of the data) when using the map function in react. As you can see, the 'standings' object is followed by two braces. When I remove one set of these braces, I can access the array that I need, but the fact that there are two sets of braces is really throwing me off. Any help would be greatly appreciated!

My function is as follows:

const TeamList = (props) => {
  console.log(props)
  let teamCards = props.teams.league.standings.map((m) => (
    <Grid key={m.team.id} item xs={12} sm={6} md={4} lg={3} xl={2}>
      <Team key={m.team.id} team={m} />
    </Grid>
  ));
  console.log(teamCards)
  return teamCards;
};

My data looks like as follows:

    
        "league": {
            "id": 39,
            "name": "Premier League",
            "country": "England",
            "logo": "https://media.api-sports.io/football/leagues/39.png",
            "flag": "https://media.api-sports.io/flags/gb.svg",
            "season": 2021,
            "standings": [
                [
                    {
                        "rank": 1,
                        "team": {
                            "id": 50,
                            "name": "Manchester City",
                            "logo": "https://media.api-sports.io/football/teams/50.png"
                        },
                        "points": 93,
                        "goalsDiff": 73,
                        "group": "Premier League",
                        "form": "WDWWW",
                        "status": "same",
                        "description": "Promotion - Champions League (Group Stage)",
                        "all": {
                            "played": 38,
                            "win": 29,
                            "draw": 6,
                            "lose": 3,
                            "goals": {
                                "for": 99,
                                "against": 26
                            }
                        },
                        "home": {
                            "played": 19,
                            "win": 15,
                            "draw": 2,
                            "lose": 2,
                            "goals": {
                                "for": 58,
                                "against": 15
                            }
                        },
                        "away": {
                            "played": 19,
                            "win": 14,
                            "draw": 4,
                            "lose": 1,
                            "goals": {
                                "for": 41,
                                "against": 11
                            }
                        },
                        "update": "2022-05-22T00:00:00+00:00"
                    },
                    {
                        "rank": 2,
                        "team": {
                            "id": 40,
                            "name": "Liverpool",
                            "logo": "https://media.api-sports.io/football/teams/40.png"
                        },
                        "points": 92,
                        "goalsDiff": 68,
                        "group": "Premier League",
                        "form": "WWWDW",
                        "status": "same",
                        "description": "Promotion - Champions League (Group Stage)",
                        "all": {
                            "played": 38,
                            "win": 28,
                            "draw": 8,
                            "lose": 2,
                            "goals": {
                                "for": 94,
                                "against": 26
                            }
                        },
                        "home": {
                            "played": 19,
                            "win": 15,
                            "draw": 4,
                            "lose": 0,
                            "goals": {
                                "for": 49,
                                "against": 9
                            }
                        },
                        "away": {
                            "played": 19,
                            "win": 13,
                            "draw": 4,
                            "lose": 2,
                            "goals": {
                                "for": 45,
                                "against": 17
                            }
                        },
                        "update": "2022-05-22T00:00:00+00:00"
                    }
                ]   
            ]
        }
    }


cduff
  • 105
  • 1
  • 1
  • 7

0 Answers0