Alex Pooley's Blog

Hello there, my name is Alex Pooley and I'm a freelance web developer residing in Perth, Western Australia. My passion is in the development of web sites that solve everyday problems. Here's a gallery of some of my notable work. If you need a web site designer or developer, contact me with further details. Lastly, you can read more about me.

Array.push() in IE

March 26th, 2006

Why don't you subscribe to my blog while you're here? I'm a freelance web developer and I blog about Ruby, Rails, and business online.

Go ahead and subscribe to my RSS feed. Thanks for visiting!

Damn it, I spent an hour on this. I was working on some code and it was working nicely in FireFox so I switched over to test out the code on IE. Big surpise (sarcasm intended), it didn’t work in IE. Anyway, it turns out that IE doesn’t support the push() method on Array objects in Javascript. At least, this is the case for me using IE 6.0.

Arrays in Javascript are dynamically resized. This is similar to Vectors in Java if memory serves me right (I haven’t used Java for a long time now). The solution to my problem was to simply define the next element in the array to the value I wanted. Memory allocation is handled magically. To mimic the ECMAScript Edition 3 spec you can do something like:

//Define the next element in array (model).
this.model[this.model.length] = p;
//Return the new length of the array.
return this.model.length;

It’s not hard now that I know. But what a pain!

Leave a Reply