Today, when we changed the code, I found that many loops of code were written in the for (var i-in data), and I usually use the for (Var i=0;i<data.length;i++)
Just looked at, the original two are different, can not be equated with the use.
<script>
Array.prototype.test = function () {};
function A () {
var arr = [1, 2];
for (var i in arr)
{
Alert (i+ "-------------" +arr[i]);
}
}
Function B () {
var arr = [1, 2];
for (var i =0;i<arr.length;i++) {
Alert (i+ "---------" +arr[i]);
}
}
A ();
b ();
</script>
We see a () will pop up three dialog boxes, which are index values: 0, 1 more a test, this test is the Array.prototype.test extension obtained.
Therefore, you cannot treat the for (var i-in data) as a shorthand for (var i = 0; i < data.length; i++).
Reference: http://www.cftea.com/c/2014/08/6290.asp
JavaScript in the for (var i in data) loop array item