I am facing an issue with populating three other arrays based on the property 'game type' from my array called 'my games'. Here is an example of the structure of the 'my games' array:
hideScore: true, started: true, startedAt: "Fri, 02 Jul 2021 09:04:25 GMT", finished: true, finishedAt: "Fri, 20 Aug 2021 15:35:37 GMT", …}
archived: false
bgGame: "#1a1f29"
client: "client test"
company: "tunisia"
country: "Tunisia"
createdAt: "2021-07-02T09:03:34.015Z"
finished: true
finishedAt: "Fri, 20 Aug 2021 15:35:37 GMT"
gameType: "test"
hideScore: true
id: "60ded6668734e65c51f50996"
language: "English"
maxLevel1: 10.47195
maxLevel2: 2.065616666666668
maxScore: 23400
name: "game test"
nbrDoors: 8
nbrPlayersPerTeam: 8
partner: "khouloud ben khssib"
playtime: 30
started: true
startedAt: "Fri, 02 Jul 2021 09:04:25 GMT"
startsAt: "Fri, 02 Jul 2021 09:03:00 GMT"
teams: (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
teamsCount: 20
textColor: "#ffffff"
updatedAt: "2021-08-20T15:35:37.348Z"
user: "609321b935e3f04d04d44337"
__v: 0
_id: "60ded6668734e65c51f50996"
I have three arrays named 'NumberofLive', 'NumberofTest', and 'NumberofDemo'.
NumberofLive: any[] =[];
NumberofTest: any[] =[];
NumberofDemo: any[] =[];
Every time I want to populate a table, I try something like this:
for(let i=0;i<this.MyGames.length; i++){
switch(this.MyGames[i].gameType) {
case 'test': {
this.NumberofTest=this.NumberofTest+this.MyGames[i];
break;
}
case 'live': {
this.NumberofLive=this.NumberofLive+this.MyGames[i];
console.log('salzem');
console.log(this.NumberofLive[1].gameType);
break;
}
default: {
this.NumberofDemo=this.NumberofDemo+this.MyGames[i];
break;
}
}
}
However, when I log my table, I find that it returns 'undefined'.