How can you iterate over an array of objects to retrieve the results of every previous game played? I encountered difficulties while attempting to iterate over non-existent values.
The desired result is an array structured like this:
newArr: [
{
"id": 1,
team: 'rockets',
record:{
first: 'win',
second: 'loss',
thrid: 'loss'
}
},
{
"id": 2,
team: 'raptors',
record:{
first: 'loss',
}
},
...
...
]
gamesPlayed: [
{
"id": 1,
"team": "rockets",
prevScore: [{
value: {results: 'win'},
prevScore: [{
value: {results: 'loss'},
prevScore: [{
value: {results: 'loss'},
prevScore: []
}]
}]
}]
},
{
"id": 2,
"team": "raptors",
prevScore: [{
value: {results: 'loss'},
prevScore: []
}]
},
{
"id": 3,
"team": "hornets",
prevScore: [{
value: {results: 'win'},
prevScore: [{
value: {results: 'win'},
prevScore: []
}]
}]
},
...
]