delete an object of an array without looping all the array
<p>I want to be able to delete an object from an array without looping all the array of objects to see if the current array element has the ID of the item I want to delete.</p>

<p>javascript:</p>

<pre><code>function CBooks() {
    this.BooksArray = [];

    this.AddBook = function(divID, sContents) {
        this.BooksArray.push(new CBook());
        pos = this.BooksArray.length - 1;
        this.BooksArray[pos].ArrayID = pos;
        this.BooksArray[pos].DivID = divID;
        this.BooksArray[pos].Contents = sContents;
    }

    this.DelBook = function(divID) {
        this.BooksArray.splice(...);
    }
}

function CBook() {
    this.ArrayID = 0;
    this.DivID = "";
    this.Contents = "";
}
</code></pre>

<p>I initialize the object like this:</p>

<pre><code>var oBooks = new CBooks();
</code></pre>

<p>I add a new book like this :</p>

<pre><code>oBooks.AddBook("divBook1", "blahblahblah");
//Creation of the div here
oBooks.AddBook("divBook2", "blehblehbleh");
//Creation of the div here
</code></pre>

<p>Now the user can click an X button in the div displaying each book, so that he can delete the book. So the X button contains:</p>

<pre><code>onclick=oBooks.DelBook(this.id);
</code></pre>

<p>Now obviously in the <strong>DelBook(divID)</strong> function I could loop through the length of the <strong>BooksArray</strong> and see each element if it's divID is equal to the parameter and splice at that point, but I want to avoid the looping.</p>

<p>Is there any way to do it ?</p>

<p>thanks in advance</p>
