AS3: Removing duplicates from an array

Actionscript

Just for shiggles (yes, I said it.), removing duplicate items from an array in one line of ActionScript 3:

var arr:Array = ["a","b","b","c","b","d","c"];

var z:Array = arr.filter(function (a:*,b:int,c:Array):Boolean { return ((z ? z : z = new Array()).indexOf(a) >= 0 ? false : (z.push(a) >= 0)); }, this);

trace(z);

This entry was posted on Wednesday, September 3rd, 2008 at 11:22 pm and is filed under Actionscript. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

One Response to “AS3: Removing duplicates from an array”

  1. Simon B Says:

    Thanks for the script!

    I’ve been trying all sorts of things to cut out duplicates, but I’m not a programmer so it’s been taking me forever!

    Simon.

Leave a Reply