It seems that I do not understand the meaning of the in keyword in JavaScript.
Take a look at this code snippet ( http://jsfiddle.net/3LPZq/ ):
var x = [1,2] for(i in x){ document.write(x[i]); }
When launched in jsfiddle, it prints not only the values contained in the array, but also all the properties and methods of the array object.
When I change it like this ( http://jsfiddle.net/4abmt/ ):
$(document).ready(function(){ var x = [1,2] for(i in x){ document.write(x[i]); }});
it prints only the values 1 and 2.
Why is this happening? Is it caused by jQuery or does the behavior of the in keyword depend on whether the document is fully loaded or not?
user500944
source share