Possible Duplicate:
Why is 'for(var item in list)' with arrays considered bad practice in JavaScript?
Is it a best practice to loop through a JavaScript array using a for..in loop?
var a = [1,2,3];
for(var x in a){
//dance
}
Or should I be using a fully written loop?
By using
for..in, you are looping through all of the Array Object’s properties, including inherited ones through the prototype model.More recent browsers have a way of making properties non-
Enumerable, meaning they won’t show up in afor..inloop. In these browsers, you can safely usefor..inon an array. HOWEVER, older browsers will behave in unexpected ways. So just because you can usefor..indoesn’t mean you should. In fact, you shouldn’t. Usefor(i=0,l=a.length; i<l; i++)for best results.