[thelist] Javascript array weirdness

Chrome admin at chrome.me.uk
Fri Aug 21 14:40:04 CDT 2009



> -----Original Message-----
> From: thelist-bounces at lists.evolt.org [mailto:thelist-
> bounces at lists.evolt.org] On Behalf Of Phil Turmel
> Sent: 21 August 2009 20:13
> To: thelist at lists.evolt.org
> Subject: Re: [thelist] Javascript array weirdness
> 
> Chrome wrote:
> [snip /]
> >
> > As you can see this is meant to populate the array this.request with
> values
> > from the theForm... Problem is that the array seems to be empty...
> The
> > strange thing is if that you call the array value by its key it has
> the
> > value but if you try to iterate through it it's blank (or seems to
> be)
> >
> > I tried inserting a hard value of this.request[1] = 'Test'; and got
> the
> > output as [undefined, 'Test']... so I tried this.request['test'] =
> 'Test';
> > and got [ ]
> >
> > So I tried replacing the this.request array as a locally defined
> array
> > called request... Still blank
> >
> > Anyone know what's going on?  I'm about to have a sub-orbital PC at
> this
> > rate ;)
> >
> 
> Hi Dan,
> 
> The Array datatype in javascript handles property get/put differently
> from other objects.  It supports numeric indices as a zero-based array,
> with automatically allocation up the highest index 'PUT' so far.  That
> explains the two values returned after assigning to index=1.
> 
> It's unclear from the copy of the Ecmascript standard I'm looking at,
> but it appears that Array's only iterate over their numeric indexed
> properties.
> 
> I suspect you want to define 'request' as a simple Object, not an
> array.
> 
> HTH,
> 
> Phil Turmel

Hi Phil

Thanks for taking a look!  However, this script is running fine on a few
sites... Here's an example:

http://chrome.me.uk/shopdev/

It is running on a few other people's test sites... for the loop iteration I
use:

for (var i in Array) { // try this on, say, the document ;)
	alert(Array[i]);
}

Arrays in JS are associative (as they are in PHP etc.) so they key really
shouldn't matter... This just seems to empty the array for no reason

I've been using that prototype object for XHR for a while now

Any other hints or clues?

Cheers

Dan




More information about the thelist mailing list