Reputation: 17
I defined my variable as:
var Players = [{
name: "personA",
score: 50
},
{
name: "personB",
score: 50
},
{
name: "personC",
score: 50
}
];
and the error is:
for (v=0;v<T;v++)
{
show += "<br/>" + Players.score[v];
}
i have already defined T and show
Upvotes: 0
Views: 622
Reputation: 623
Players.score[v]
is undefined.
It should be Players[v].score
.
You defined your Players
variable as an array, so you have to loop over this array and not the score
key.
Upvotes: 1
Reputation: 167172
You forgot to specify which Player
. Change the code to use Players[v].score
:
for (v = 0; v < T; v++) {
show += "<br/>" + Players[v].score;
}
The Players
is an array, not the score
.
Upvotes: 1