[thelist] Javascript array weirdness

Chrome admin at chrome.me.uk
Tue Aug 25 17:20:19 CDT 2009


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

Hi all

I've noticed with this that the issue only arose on a site with Mootools
(driving Slimbox)... Does anyone know why this might happen?

Cheers

Dan




More information about the thelist mailing list