1

I have an ArrayCollection that I want to have all null or empty values removed.

What line in the code might accomplish this?

Dave
  • 11
  • 2

1 Answers1

1

This is the faster way in terms of performance:

<mx:Script><![CDATA[
    public function cleanArrayCollection(collection:ArrayCollection):ArrayCollection{
        var currentArray:Array = null;    
        var newCollection:ArrayCollection = new ArrayCollection();
        for(var i:int = 0; i < collection.length; i++){
            currentArray = collection.getItemAt(i);
            if(currentArray != null && currentArray.length != 0){
                newCollection.addItem(currentArray);
            }
        }

        return newCollection;
    }
]]></mx:Script>

Edit: Removed critical bugs in logic.

rzetterberg
  • 10,146
  • 4
  • 44
  • 54