I found that there is a difference between for loop and for-in loop in javascript. When I define a new array: var a=new Array(); Then I put some value into in but not contiguously for example: a[0]=0;a[1]=1;a[4]=4; When I use for(i=0;i<5;i++) to get the value and use alert to show it, it's different from using for(i in a). The previous one will show elements in index 2,3 which shows "undefined" while for-in will show only index 0,1,and 4. Can anybody tell me why?
Aucun commentaire:
Enregistrer un commentaire