as3 array remove by index

actionscript-3, arrays, indexing

Solution

You want splice

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#splice%28%29

Array.splice(starting point, remove count);

 var newArray:Array = myArray.splice(2, 1); //this removes whatever is at index 2 and returns it in a new array.

Change your function to

function removeit(myindex) {
    animals.splice(myindex, 1);
}

Problem

I have an array 'cat', 'dog', 'budgie' and want to remove the item by index. At the moment I have ``` function removeit(myindex) { animals[myindex] = animals.pop() } ```

Original source