我有一个 ArrayCollection,我想删除所有空值或空值。
代码中的哪一行可以做到这一点?
就性能而言,这是更快的方法:
<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>
编辑:删除了逻辑中的关键错误。