[thelist] Using for loops with a twist

Dan Parry dan at virtuawebtech.co.uk
Mon Apr 2 20:01:18 CDT 2007


I'm not sure a 'why' question should be confused with a 'what if'
question... It's good practice for encountering users :)

Sorry for top-posting

-- 
Dan

-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of Christian Heilmann
Sent: 03 April 2007 00:11
To: thelist at lists.evolt.org
Subject: Re: [thelist] Using for loops with a twist

> > 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/
-- 

* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester 
and archives of thelist go to: http://lists.evolt.org 
Workers of the Web, evolt ! 


-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.24/742 - Release Date: 01/04/2007
20:49





More information about the thelist mailing list