# Remove an element from array

**URL:** https://forum.kirupa.com/t/remove-an-element-from-array/193113
**Category:** Uncategorized
**Created:** [July 4, 2006, 1:54pm UTC](https://forum.kirupa.com/t/remove-an-element-from-array/193113 "2006-07-04T13:54:13Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ukko](https://avatars.discourse-cdn.com/v4/letter/u/e68b1a/32.png) [@ukko](https://forum.kirupa.com/u/ukko)
#### Post date: [July 4, 2006, 1:54pm UTC](https://forum.kirupa.com/t/remove-an-element-from-array/193113/1 "2006-07-04T13:54:13Z")

</div>

I have created a bit of AS that attaches library images from an array 1 at a time, but i am having difficulty remove the element/images once it has been displayed from the array and stage.

output

Entry lunchbox(12)  
Array No:12 was removed  
Entry toydoll(20)  
Array No:20 was removed  
Entry newspaper(14)  
Array No:14 was removed  
Entry pictureframe(17)  
Array No:17 was removed  
Entry fork(7)  
Array No:7 was removed  
Entry jug(9)  
Array No:9 was removed  
Entry key(10)  
Array No:10 was removed  
Entry pan(15)  
Array No:15 was removed  
Entry spoon(18)  
Array No:18 was removed  
Entry trophy(21)  
Array No:21 was removed

//should not have been deisplayed again  
\*\*Entry fork(7)  
Array No:7 was removed

\*\*Entry chair(3)  
Array No:3 was removed

//should not have been deisplayed again  
**Entry fork(7)  
Array No:7 was removed**

been going round in circles with this.

heres my code so far

```auto

var picArray:Array = new Array();
picArray[0] = "bottle";
picArray[1] = "bucket";
picArray[2] = "carrierbag";
picArray[3] = "chair";
picArray[4] = "coat";
picArray[5] = "cushion";
picArray[6] = "envelope";
picArray[7] = "fork";
picArray[8] = "hat";
picArray[9] = "jug";
picArray[10] = "key";
picArray[11] = "kitchenroll";
picArray[12] = "lunchbox";
picArray[13] = "mirror";
picArray[14] = "newspaper";
picArray[15] = "pan";
picArray[16] = "phonebook";
picArray[17] = "pictureframe";
picArray[18] = "spoon";
picArray[19] = "toyboat";
picArray[20] = "toydoll";
picArray[21] = "trophy";
picArray[22] = "trouser";
picArray[23] = "vase";

var depths:Number = -1;
var rndNum:Number = olddepth;

function attachPic()
   {
      rndNum = Math.floor(Math.random() * picArray.length);
      _root.blank1.attachMovie(picArray[rndNum], picArray[rndNum] + "Clip", depths++);
      return ("Entry " + picArray[rndNum] + "(" + rndNum + ")");
   }

trace(attachPic("picArray: ", +picArray[rndNum]));

function picRemove(toRemove:String)
   {
      for (var i:Number = 0; i < picArray.length; i++)
         {
            if (picArray* == toRemove)
               {
                  _root[picArray* + "Clip"].removeMovieClip();
                  picArray.splice(i, 1);
                  return ("Array No:" + i + " was removed");
               }
         }
      return ("Failed to remove an entry.");
   }

trace(picRemove(picArray[rndNum]));
//trace(picArray);

```
