The organization of your arrays is wrong. You have an array called _players which suggests that you want it to store several players. And that’s what you have now: You’ve got player 1 whose first name is Phil. Player 2 has a last name of Foden. Player 3 is aged 23 and so on. I guess you expect that array to have 3 players, not 9. So the _players array needs to have 3 objects, like so:
{
firstName:'Phil',
lastName:'Foden',
age:23
}
Then Phil Foden, aged 23 is just one player. And then you could access Erling Haaland like so:
console.log(`Best player in that match was ${team._players[2].firstName} ${team._players[2].lastName}`)
Each player should be an object containing three properties: firstName , lastName , and age . Would’nt that mean my current syntax is correct??. when i call index [9] it returns [object object] since that is the game object being pushed to the _games array?? Am i understanding complety wrong now ??
console.log(team._games[0]) only prints out each index point but i want the opponent,team points and opponent points all printed on the same line as one cohesive.
That’s what you see in my code snippet. In your code you have objects with only one property each.
You need to access the property value in that object if you want to print it in a string literal. index [9]just returns the object with both, key and value in it.
Omg so sorry i see my error now! fixed the code!! and got the correct output. I see what i was doing wrong now! Thank you for explaining. I tohught that since the properties were in the same array i belived that it would read it induvidually.
I now understand that for each player object the firstName, LastName and age all should be in the same and not seperate objects as i did in my first code