# Problem removing item from array using splice

**URL:** <https://forum.kirupa.com/t/problem-removing-item-from-array-using-splice/146091>\
**Category:** Uncategorized\
**Created:** [April 28, 2005, 4:35am UTC](https://forum.kirupa.com/t/problem-removing-item-from-array-using-splice/146091 "2005-04-28T04:35:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lisaad](https://avatars.discourse-cdn.com/v4/letter/l/5e9695/32.png) [@lisaad](https://forum.kirupa.com/u/lisaad)\
**Post date:** [April 28, 2005, 4:35am UTC](https://forum.kirupa.com/t/problem-removing-item-from-array-using-splice/146091/1 "2005-04-28T04:35:28Z")

</div>

I’m having trouble removing an element from an array. my array is filename, and i want to randomly select one item, then remove it so it isn’t selected again.

here’s my code:

```auto

selectRandom = function(){
    filename = ["p1_1.swf", "p1_2.swf", "p1_3.swf", "p1_4.swf", "p1_5.swf", "p1_6.swf"];
    path = "http://a.parsons.edu/~lisa/spring05/interactivity/final/swfs/";
    i = filename.length;    
    k = Math.floor(Math.random()*i);    
    randomFile = filename[k];
    filename.splice(k,1);    
    return(randomFile);                
    return(path);        
}

```

is there something I’m missing?
