[thelist] Using for loops with a twist
Christian Heilmann
codepo8 at gmail.com
Mon Apr 2 18:10:43 CDT 2007
> > var arr = [1,2,0,4,5];
> > for(var i=0;arr[i];i++){
> > alert(arr[i]);
> > }
> >
> > However, as 0 is falsy, you need to check properly:
> >
> > var arr = [1,2,0,4,5];
> > for(var i=0;arr[i]!==undefined;i++){
> > alert(arr[i]);
> > }
>
> What happens to this if you do:
>
> delete arr[1];
>
> ?
It stops the loop, but why would you want to delete an array element?
--
Chris Heilmann
Book: http://www.beginningjavascript.com
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/
More information about the thelist
mailing list