Search code examples
actionscript-3flashapache-flexarraycollection

ActionScript 3 - Removing Duplicates in ArrayCollection


I have an ArrayCollection of a list of usernames and user id's. In this list there are duplicates that I need to remove. I've searched the internet and while there are a lot of example of this using Arrays, I can't find any clear examples using ArrayCollection's.


Solution

  • The should be simpler then the other solution.

    function removeDuplicatesInArray(val:*, index:uint, array:Array):Boolean {
      return array.indexOf(val) == array.lastIndexOf(val);
    }
    
    function removeDuplicatesInCollection(collection:ArrayCollection):ArrayCollection {
      collection.source = collection.source.filter(removeDuplicatesInArray);
    
      return collection;
    }