http://code.google.com/p/chromium/issues/detail?id=50316
What steps will reproduce the problem?
Execute:
var arr = [0, 1, 2];
for (var i=0; i<arr.length; i++) {
arr[i] = -1;
console.log(arr);
}
What is the expected result?
[-1, 1, 2]
[-1, -1, 2]
[-1, -1, -1]
What happens instead?
3 [-1, -1, -1]
What steps will reproduce the problem?
Execute:
var arr = [0, 1, 2];
for (var i=0; i<arr.length; i++) {
arr[i] = -1;
console.log(arr);
}
What is the expected result?
[-1, 1, 2]
[-1, -1, 2]
[-1, -1, -1]
What happens instead?
3 [-1, -1, -1]
本文介绍了一个JavaScript编程中关于数组操作的常见错误实例。通过一个简单的示例代码,展示了当遍历数组并同时修改其元素时可能遇到的问题,并记录了执行过程中的输出结果。
304

被折叠的 条评论
为什么被折叠?



