AS3 Quick Code Snippet: remove duplicates in an Array with AS3

AS3 Quick Code Snippet: remove duplicates in an Array with AS3

AS3 Quick Code Snippet: remove duplicates in an Array with AS3

This small, quick AS3 code snippet shows how duplicates in an Array can be removed with Adobe ActionScipt 3.0.
This can come in handy when you want to have a unique set of Array data inside your AS3 project.

This code example is based on a Array, but can very easily be adapted for Dictionary’s, ArrayCollections or ArrayLists.

function removeDuplicatesInArray(source:Array):void {
    var i:int; var j: int;
    for (i = 0; i < source.length - 1; i++){
        for (j = i + 1; j < source.length; j++){
            if (arr[i] === arr[j]) source.splice(j, 1);
        }
    }
}

More interesting ActionScript code snippets?
Have a look in our Creative-Geeks ActionScript 3 category


About the Author

Daan is a Creative-Geek who loves learning and sharing new techniques! Follow him on Twitter to keep up to date with the Creative-Geeks blog and other subjects. Contact him on e-mail : info[at]creative-geeks.com.