Is there a quicker way besides iterating thru all entries in the associative array
Related to - How do I delete a value from an Object-based associative array in Flex 3?
Is there a quicker way besides iterating thru all entries in the associative array
Related to - How do I delete a value from an Object-based associative array in Flex 3?
There are a few solutions to clear an associative array (which is the same as a dynamic object):
The quickest one is assigning a new array. In most cases this will be the preferred solution.
myArray = [];Removing all keys from the array. It will have the same effect as solution one. However, the array instance stays the same.
for (var key:String in myArray)
delete myArray[key];Setting all values in the array to null. The array instance will stay the same and all of it's keys are preserved. Only the array's values are set to null.
for (var key:String in myArray)
myArray[key] = null;I think myArray = null; should remove the whole bunch.
UPDATE
var i:int=-1;
for(;myArray[++i];)
{
delete myArray[i];
myArray[i] = null;
}
OR
for(var r:String in myArray)
{
delete myArray[i];
myArray[r] = null;
}
myArray[r] = null; doesn't work. You have to use delete myArray[r]; otherwise the index won't be removed from the array.myArray[r] = null; should be omitted. You are currently deleting and adding back a new entry with the value null.