I’m trying to access an array inside of an object that comes in a response:
getMatches().then((matches) =>{
let possibleDraws = []
console.log(matches)
console.log(typeof matches)
matches.forEach(match => {
if(isPossibleDraw(match)){
possibleDraws.push(match)
}
console.log(match.homeForm)
})
console.log(possibleDraws)}).catch((err) =>{
console.log(err)})
console.log(matches)
returns correctly an array with just one value for testing purposes:
0:
awayForm: (4) ['L', 'D', 'W', 'D']
awayTeamID: 15994
awayTeamName: "Maritzburg United U23"
homeForm: (4) ['L', 'D', 'W', 'D']
homeTeamID: 15990
homeTeamName: "Chippa United U23"
leagueID: 734
matchID: 793855
season: 2021
[[Prototype]]: Object
length: 1
[[Prototype]]: Array(0)
However, when accessing match.homeForm
, it returns “Undefined is not an object”, even when match.homeForm
does exist (based on the last console.log) . I even mocked the response of getMatches()
to the same array (original function calls an API and get the response as a promise) and it works perfectly fine, so I really have no idea what could be happening here.