[thelist] Javascript array weirdness

Phil Turmel pturmel-webdev at turmel.org
Fri Aug 21 14:13:22 CDT 2009

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

I suspect you want to define 'request' as a simple Object, not an array.


Phil Turmel

Need to contact me offlist?
   Drop -webdev or you probably won't get through.

More information about the thelist mailing list