Removing array items by index

Posted: August 26, 2008 in Flex

When removing items from an array via its index number, remember to always start from the end and work your way to the beginning. If you don’t, and are removing more than one item, the index you where looking for will no longer be the correct item because one or more have already been removed and the indexes have been reassigned to fill the gap.

Correct Example: (I am using the Cairngorm framework in this example.)

for (var j:int=grid1.selectedIndices.length-1; j>=0; j--) {

Also remember, that “indices” is the plural form of “index”.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s