What I'm trying to do is loop through an object getting the total times that each candidate appears and print that to the page.
I've have been racking my head on this one. I'm new to javascript and working with objects is something very new to me.
Thank you for the help!
var entry = [
{
candidate : "guy1",
rank : 1,
state : "AK",
vote_count : "2"
},
{
candidate : "guy2",
rank : 1,
state : "MI",
vote_count : "3"
},
{
candidate : "guy3",
rank : 1,
state : "AK",
vote_count : "5"
},
{
candidate : "guy2",
rank : 1,
state : "AL",
vote_count : "4"
},
{
candidate : "guy2",
rank : 1,
state : "FL",
vote_count : "9"
},
{
candidate : "guy1",
rank : 1,
state : "MN",
vote_count : "7"
}
];
for ( var i = 0, l = entry.canidate.length; i < l; i++ ) {
guy1 += entry.canidate[i];
}
console.log(guy1);
Aucun commentaire:
Enregistrer un commentaire