# Search and Destroy

**URL:** <https://forum.kirupa.com/t/search-and-destroy/99398>\
**Category:** Uncategorized\
**Created:** [January 18, 2004, 3:36pm UTC](https://forum.kirupa.com/t/search-and-destroy/99398 "2004-01-18T15:36:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kole](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kole](https://forum.kirupa.com/u/Kole)\
**Post date:** [January 18, 2004, 3:36pm UTC](https://forum.kirupa.com/t/search-and-destroy/99398/1 "2004-01-18T15:36:29Z")

</div>

I have a box with 5 pieces of paper inside  
myArray1 = new Array (“1”,“2”, “3”, “4”, “5”);

I am going to chose a piece at random from the box

$i = random(5);  
trace(myArray1[$i]);

That piece has now been removed from the box, therefor it has to be removed from the array, now I can’t find any tutorials on how to remove from mid-array only begining and end, so I thought of this,

```auto

for (var $loop = 0; $loop < myArray1.length(); $loop++)
   {
   if ($loop <> $i)
      {
      myArray2 = new Array();
      myArray2.push(myArray1[$loop]);
      }
   }
trace(myArray2);

```

Now maybe I am wrong in how I have set this up, but im thjinking if the loop index of the random piece is equal to the random number, then skip that, else, put all the other pieces in a new box.  
but when i trace the 2nd array, it displays the random value.

I don’t know what I am doing wrong. Is there any way to move everything from an array into a new array WITHOUT a certain element? I mean I know you can move a certain element via its array possition, any form of array.pushNOT($n, ($n+1))

:hangover:
