views:

278

answers:

2

I'm working with an array in AS3, which is sparse by default. I make an array and add a value to it at a given position. I nullify it's contents at that index. It retains that index value, but nullifies the contents. The issue is that the length still traces the same. Is there a way to actually remove that index without modifying any of the other indexes?

ex: 
array:Array = new Array();
array[ 7 ] = new Array();
array[ 16 ] = new Array();
array[ 16 ] = null;

Edit: I want the array the array to stay as small as possible, so that in the example above the array would trace as length 7.

A: 

Try this

array.splice(7,1)

splice()

jcopenha
This changes the indexes of all elements after 7.
fenomas
+1  A: 

use the delete operator ... still, length will remain 8 ... setting the value for key 7 to null still means, there is a value for key 7, since Array may contain any values, including null. if you really use sparse arrays, then consider using flash.utils::Dictionary ... if key order matters, then look into flash.utils::Proxy ... or make some data structure, that does not use array access, but has some getVal and setVal methods instead ...

back2dos
I guess my example was too simple without realizing it. I have a scenario where I have a multidimensional array. If I remove that last index, I want the length to display as the last non-null value.Ex: the same as abovearray:Array = new Array();array[ 7 ] = new Array();array[ 16 ] = new Array();array[ 16 ] = null;I want the array to trace as 7, if that makes sense? I just want to keep this array as small as possible because it could potentially get very large.
grey
edit: moved above.
grey