Unique records in AS3

I’m sure others already know this little trick – but in case you didn’t…

The filtermethod for Arrays in Actionscript 3.0 comes in handy if you want to (ahem) *filter* certain elements out of your array :

var tmpArray:Array = ["oranges", "apples","oranges", "pineapple", "carrots", "oranges"];
var fruits:Array = tmpArray.filter(function(e, i, a){
   var isUnique:Boolean = (a.indexOf(e) == i);
   return (isUnique);
}, this);

Continue reading