我有对象:

var votes = {
  "Alex": {president: "Bob"},
  "Bob": {president: "Mary"},
  "Cindy": {president: "Cindy"},
  "Devin": {president: "Louise"},
  "Ernest": {president: "Fred"},
  "Fred": {president: "Louise"},
  "Gail": {president: "Fred"},
  "Hermann": {president: "Ivy"},
  "Ivy": {president: "Louise"},
  "John": {president: "Louise"},
  "Kerry": {president: "Fred"},
  "Louise": {president: "Nate"},
}


我将如何计算总统的所有选票?具体来说,如何显示“路易”票数最多?

到目前为止,我唯一要了解的是谁投票给谁:

for (i in votes)
{
     console.log(votes[i].president);
};

最佳答案

var president = [];

for(k in votes) {
    president.push(votes[k]['president']);
}


此后,您需要计算每个元素在
president数组。

10-01 20:51