我正在用 JavaScript 编写代码并检测到这种我无法解释的奇怪行为。
for (i in bubbles){
bubbles[i].string = "some stuff!" // <- no errors here
results[0] = i - 1
results[1] = i + 1
results[2] = parseInt(i) + 1
}
当i = 1
这种情况发生时
results[0] -> 0
results[1] -> 11
results[2] -> 2
这甚至可能吗?也许是由于代码中的其他错误。我试图隔离上面的情况,但是,如果你需要它,这里是整个代码
for (i in bubbles){
if (bubbles[i].check()){
// define which boubble has been clicked and start dragging
bubbleDrag[2] = bubbles[i].check();
bubbleDrag[1] = i;
bubbleDrag[0] = true;
// define where to check to avoid overlapping dates
if (i != 0 && i < bubbles.length - 1){
bubbleDrag[3] = i - 1;
bubbleDrag[4] = i + 1;
} else if (i == 0 && bubbles.lenght > 1){
bubbleDrag[3] = i + 1;
} else if (i == bubbles.lenght - 1){
bubbleDrag[3] = i - 1;
}
}
}