I have a list of games(objects) inside a object, which is inside an array of players. I'm trying to check which object inside the array is the current user to than go in the games array and a print out the objects property.
Go through PlayerList to find currentUsers
for (let i = 0; i < model.playerList.length; i++) {
if (model.currentUser == model.playerList[i].userName)
//Go Through games from the player to print the game information
{
for (let i = 0; i < model.playerList[i].game.length; i++) {
html += `<div>
<p> Spillnr: ${model.playerList[i].game[i].gameNumber}</p>
<p> Ord: ${model.playerList[i].game[i].word}</p>
<p> Dato: ${model.playerList[i].game[i].date}</p>
<p> Forsøk: ${model.playerList[i].game[i].attempts}</p><hr>
</div>`;
}
} else { console.log('ok') }
I'm getting the properties of game from different objects inside playerList instead of only getting from the currentUser.
HELP PLEASE
model.playerList = [ { userName: 'MasterLetters', age: 27, password: '123456', game: [{ gameNumber: 1, date: '15/01/2022', word: 'bukse', attempts: 9, }, { gameNumber: 2, date: '17/01/2022', word: 'kakse', attempts: 7, }, ] },the result expected is to print the game info for each player as long as theyr logged in currentUser`