Jump to content

Remove from associative array


The Little Guy

Recommended Posts

I have an array that could look simular to this:

playersArr = Array(1 => 'cat', 3 => 'fish', 9 => 'bird', 5 => 'mouse');
function removePlayer(id){
playersArr.splice(id,1);
}

 

Then there is a function, that is supposed to remove an element from the array (removePlayer).

 

I then have a button next to each one to remove it from the array. So if you want to remove one you press the button and it fires up removePlayer() and removes that id from the array.

 

The problem is that if I remove from the array 1, 3, 9, 5 in that order (one at a time) it will remove all but #5.

But...

If I remove from the array 5, 9, 3, 1 in that order (one at a time) it will remove them all.

 

does that make any sense???

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.