【发布时间】:2016-03-18 13:33:17
【问题描述】:
我使用构造函数来创建对象
function player(name,state,score,marker,combination) {
this.name = name;
this.state = state;
this.score = score;
this.marker = marker;
this.combination = combination;
}
属性“组合”应该是一个数组。在创建 PLAYER 对象实例时,我以这种方式设置数组:
players[players.length] = new player(name,false,0,'marker',[]);
然后我在“组合”属性里面动态设置数组的值,但是我不知道如何找到当前数组的长度
players[i].combination[ANONYMOUS ARRAY.length] = some value;
我发现我在这里遗漏了一些关键知识。请问有人可以帮我吗?建议在对象的属性中设置数组/处理这样的数组的正确方式???
【问题讨论】:
-
players[i].combination[players[i].combination.length] = some value;或更好的players[i].combination.push(some value); -
谢谢,我使用了 push() 选项。这行得通!
标签: jquery arrays object properties