Can't empty JS array....

Posted by solefald on Stack Overflow See other posts from Stack Overflow or by solefald
Published on 2010-04-19T20:28:44Z Indexed on 2010/04/19 20:33 UTC
Read the original article Hit count: 338

Filed under:
|
|

Yes, I am having issues with this very basic (or so it seems) thing. I am pretty new to JS and still trying to get my head around it, but I am pretty familiar with PHP and have never experienced anything like this. I just can not empty this damn array, and stuff keeps getting added to the end every time i run this.

I have no idea why, and i am starting to think that it is somehow related to the way chekbox id's are named, but i may be mistaking....

id="alias[1321-213]", id="alias[1128-397]", id="alias[77-5467]" and so on.

I have tried sticking

checkboxes = []; and checkboxes.length = 0;

In every place possible. Right after the beginning of the function, at the end of the function, even outside, right before the function, but it does not help, and the only way to empty this array is to reload the page. Please tell me what I am doing wrong, or at least point me to a place where i can RTFM. I am completely out of ideas here.

function() {

    var checkboxes = new Array();
    checkboxes = $(':input[name="checkbox"]');

        $.each(checkboxes,
            function(key, value) {
                     console.log(value.id);                            
                     alert(value.id);
          }
        );
     checkboxes.length = 0;                          
}

I have also read Mastering Javascript Arrays 3 times to make sure I am not doing something wrong, but still can't figure it out....

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about arrays