-1

我需要一些帮助来解决问题。我有这样的数组

var teams= ["real madrid","manchester united","real madrid","paris saint german"...]

.而且我需要创建数组来保存这个数组中每个团队的信息,比如

var real madrid = [ goals:0,wins:0,loses:0]

我试过这段代码

for(i=0;i<teams.length;i++)[
var teams[i].toString() = [goals:0,wins:0,loses:0];
]

但它没有用。

4

1 回答 1

1

如果你真的想要,你可能会想出一些数组组合来保存它,但你可能只想要一些像这样的对象:

var teams= ["real madrid","manchester united","real madrid","paris saint german"],
    stats = {}, i, currentTeam;

for(i=0;i<teams.length;i++) {
  currentTeam = teams[i];
  stats[currentTeam] = {goals: 0, wins: 0, losses: 0};
}

然后您将能够像这样“索引”您的统计数据:stats['real madrid'].goals stats['manchester united'].losses 等

于 2013-06-08T09:38:34.617 回答