Dav*_*edy -1 javascript arrays for-loop for-in-loop
这有效:
for (var i = 0; i < this.size(); i++) {
values.push(this.cards[i].value);
}
Run Code Online (Sandbox Code Playgroud)
但这不是:
for (var card in this.cards) {
values.push(card.value);
}
Run Code Online (Sandbox Code Playgroud)
为什么?
因为在for...in循环中,变量是键,而不是值.
它应该是:
for (var card in this.cards) {
values.push(this.cards[card].value);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
73 次 |
| 最近记录: |