# Spliceing from array problem, a little help please

**URL:** <https://forum.kirupa.com/t/spliceing-from-array-problem-a-little-help-please/37881>\
**Category:** Uncategorized\
**Created:** [December 15, 2003, 3:51pm UTC](https://forum.kirupa.com/t/spliceing-from-array-problem-a-little-help-please/37881 "2003-12-15T15:51:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![welshy](https://avatars.discourse-cdn.com/v4/letter/w/2bfe46/32.png) [@welshy](https://forum.kirupa.com/u/welshy)\
**Post date:** [December 15, 2003, 3:51pm UTC](https://forum.kirupa.com/t/spliceing-from-array-problem-a-little-help-please/37881/1 "2003-12-15T15:51:56Z")

</div>

Thanks to marz for suggesting that I use splice in my array yesterday, I took your advise on board and my prototype nearly works, and for the life of me I cant understand why it doesn’t remove all the elements from the array, It removes 1 and 2 fine but doesn’t remove 3 and 4, I don’t know if anyone could explain to me why this doesn’t work. Ive included the entire code below; if you could help me out I’d be chuffed, cheers.

\_root.Work.\_visible = false;  
\_root.one.\_visible = false;  
\_root.two.\_visible = false;  
\_root.three.\_visible = false;  
\_root.four.\_visible = false;  
myfirstarray = new Array();  
myfirstarray[0]=\_root.one,  
myfirstarray[1]=\_root.two,  
myfirstarray[2]=\_root.three,  
myfirstarray[3]=\_root.four;  
//generate random number  
\_root.button.onPress = function() {  
randomnumber = Math.round(Math.random()\*(myfirstarray.length-1));  
selectednumber = myfirstarray[randomnumber];

```
if (selectednumber == _root.one) {
	myfirstarray.splice(0, 1);
	trace(myfirstarray);
	_root.one._visible = true;
	_root.two._visible = false;
	_root.three._visible = false;
	_root.four._visible = false;
	if (myfirstarray.length&lt;=0) {
		Work._visible = true;
	}
}
if (selectednumber == _root.two) {
	myfirstarray.splice(1, 1);
	trace(myfirstarray);
	_root.two._visible = true;
	_root.one._visible = false;
	_root.three._visible = false;
	_root.four._visible = false;
	if (myfirstarray.length&lt;=0) {
		Work._visible = true;
	}
}
if (selectednumber == _root.three) {
	myfirstarray.splice(2, 1);
	trace(myfirstarray);
	_root.two._visible = false;
	_root.one._visible = false;
	_root.three._visible = true;
	_root.four._visible = false;
	if (myfirstarray.length&lt;=0) {
		Work._visible = true;
	}
}
if (selectednumber == _root.four) {
	myfirstarray.splice(3, 1);
	trace(myfirstarray);
	_root.two._visible = false;
	_root.one._visible = false;
	_root.three._visible = false;
	_root.four._visible = true;
	if (myfirstarray.length&lt;=0) {
		Work._visible = true;
	}
}
_root.output.text = selectednumber.text;

```

};  
\_root.button.onRelease = function() {  
};
