Array extensions

Way back when, I wrote a library to extend the Array object to use with Internet Explorer 5.0, which still didn’t include the ECMAScript 3rd edition methods. I had also defined several other functions I found useful. Recently, I found this file and decided to update it with the new Mozilla methods. So, if you’re so inclined, take a look at the zArray library.

**Update: ** I really wish I had noticed that Erik had already done something similar…really could’ve saved me the time. Oh well.

**Update 2: ** Erik correctly pointed out that my implementation of every() was faulty. I have fixed it and updated zArray to version 1.01.


  1. Erik Arvidsson

    I thought you blogged about this when I released that? Well, yours works without call which will help non ECMAScript edition 3 compatible engines.

    Didn&#039t you forget the object argument to every?

  2. Nicholas C. Zakas

    Yeah, I did blog about it when you posted it. But I have this thing about reading blogs...I never follow the links while I&#039m reading because I get too distracted. I thought that the link you had was to source for your own methods, not for an emulation of the Mozilla methods. It was only after I stopped by again and clicked that I saw the Mozilla ones as well.

    When I originally wrote this library oh so long ago, I wrote it to incorporate splice(), push(), pop(), shift(), and unshift() into non-ECMAScript 3rd edition browsers, so I figured I&#039d just keep the trend alive with this one.

    You&#039re right, the every() method is messed up. Gotta fix that. Thanks for pointing that out.

  3. christian biesinger

    Your implementation of every seems to return false for a zero-length array... There&#039s a mozilla bug report about this behaviour, https://bugzilla.mozilla.or..., so mozilla will probably change to true for calling every on an empty array.

    (looks like Erik&#039s implementation returns true for an empty array)

  4. Nicholas C. Zakas

    Thanks for pointing that out, Christian. I&#039ll take a look.

  5. Bruce Weirdan

    It seems the link ( is broken. It gives 404 Not found

  6. Nicholas C. Zakas

    Yes, the filename changed with the version number. You should always go directly to the download page and not rely on direct URLs to the zip file.

  7. José Jeria

    Nicholas, I think you should point out that this will brake named arrays. I also extended the Array object in a project (only the indexOf method) and this turned out to be a major headache.

    Problem is this, you do a for each loop in your named array and it will also inlcude all the attached methods:
    var aObjects = [];
    aObjects["myObj"] = {};
    aObjects["myOtherObj"] = {};

    for(var i in aObjects)
    alert(i + " = " + aObjects[i]);

Understanding JavaScript Promises E-book Cover

Demystify JavaScript promises with the e-book that explains not just concepts, but also real-world uses of promises.

Download the Free E-book!

The community edition of Understanding JavaScript Promises is a free download that arrives in minutes.