Creating an object similar to an array or extending the Array prototype
<p>I'm trying to make something similar to an array.</p>

<p>I need to be able to "release" an Index (set its value to undefined) but I don't want to lose the Index.
The "released" Indexes should be re-used whenever a new item is put into the array.</p>

<p>I'd like to be able to do something like:</p>

<pre><code>example = new MyArray();

a = example.leaseIndex(); // returns 0
example[a] = "example value";

b = example.leaseIndex(); // returns 1
example[b] = "another value";

example.releaseIndex(0);

c = example.leaseIndex(); // returns 0
example[c] = "yet another value";
</code></pre>

<p>In my example leaseIndex finds an available index or if none are available pushes a new item onto the array and returns the index of that item.</p>

<p>I want to do this so that the array doesn't just grow bigger over time needlessly.
I can't remove the "released" items as each item in the array contains a reference to another item in the same array.</p>

<p>I've had minor successes with functions and arrays outside of the main one to keep track of the available indexes and assign and release them, but ideally I'd like the functionality to be part of the main array.</p>

<p>Would I have to add my functions to the Array (or its prototype) or is there another way? As not all my arrays need this functionality.</p>

<p>Hope this makes sense :/</p>

<p><strong>update</strong></p>

<p>I am trying to store wiring loom layouts, which are essentially a net diagram (points and information as to how the points are connected).</p>

<p>The picture shows an example loom. It has 3 Connectors; Red (0) with 2 Lines, Yellow (1) with 3 Lines and Green (2) with 2 Lines.
One of the lines on the Red Connector is Spliced (allowing multiple Lines to connect to a Single Line, the blue square)</p>

<p><img src="http://i.stack.imgur.com/pB0AB.png" alt="enter image description here"></p>

<p>This is how that loom would be stored.</p>

<pre><code>loom = {
    points = [
        { self: 0, list: [ 2 ] },
        { self: 1, list: [ 7 ] },
        { self: 2, list: [ 0 ] },
        { self: 3, list: [ 7 ] },
        { self: 4, list: [ 6 ] },
        { self: 5, list: [ 7 ] },
        { self: 6, list: [ 4 ] },
        { self: 7, owner: 1, list: [ 1, 3, 5 ] }
    ],
    connectors = [
        [ 0, 1 ],
        [ 2, 3, 4 ],
        [ 5, 6 ]
    ]
}
</code></pre>

<p>the elements in the connectors array contain the indexes of points in the points array.
the list array inside each points object contains the index of its destination(s) which are points too.</p>

<p>Im trying to make functions to help make managing the indexes easier, just wanted to know if there is a way to extend the array, or make something similar that incorporates the functionality. Using static functions would be OK and is what I've been using. I just wanted to see if i could extend the array, or use something like one so I didnt need to use the static functions. </p>
