This has bothered me for a while, see my jsfiddle: http://jsfiddle.net/DHR8Q/, which contains the following javascript code:
var id = "11111;22222;33333";
id = id.split(";");
alert(typeof id);
for (var i in id){
alert(id[i]);
}
When I split the variable id
by the character ";", then I use the for loop, I would assume that i == 0,1,2
because the string id
was split into 3 parts, but this is not what happens. In reality i == 0,1,2,3,4...
. Why does JavaScript do this?