Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Array::splice in ActionScript 3

I am trying to remove an object from an array, but for some reason it's not working. I am under the impression that a splice accepts 2 parameters: first, the position in the array to begin at. And for parameter 2, how many to delete from then on out.

I just want to delete one entry so I am doing this:

array.splice(i,0);

But it isn't working. Can someone tell me what I am doing wrong and enlighten me on how it is supposed to work.

like image 777
numerical25 Avatar asked Jan 12 '10 01:01

numerical25


People also ask

How does an array splice work?

The splice() method is a built-in method for JavaScript Array objects. It lets you change the content of your array by removing or replacing existing elements with new ones. This method modifies the original array and returns the removed elements as a new array.

What is array in Actionscript?

Actionscript Course Arrays are variables that store multiple values in a single variable name. So, an Array is a variable with an ordered list of values.

How do you splice an array inside an array?

Use the array methods slice and splice to copy each element of the first array into the second array, in order. Begin inserting elements at index n of the second array. Return the resulting array. The input arrays should remain the same after the function runs.

Why is splice not working on array?

It's not working because you are removing items from the array while looping through the keys. When you remove an item, it will rearrange the other items depending on how the array is implemented internally, and you end up with a loop that doesn't iterate over the keys that you expect.


1 Answers

If you want to remove one element, you call splice(index, 1).

like image 152
Anon. Avatar answered Sep 28 '22 21:09

Anon.