AS3: Remove Duplicates in an Array


/ Published in: ActionScript 3

I found this awesome function that allows you to easily remove duplicate values.


Copy this code and paste it in your HTML
  1. function removeDuplicate(arr:Array) : void{
  2. var i:int;
  3. var j: int;
  4. for (i = 0; i < arr.length - 1; i++){
  5. for (j = i + 1; j < arr.length; j++){
  6. if (arr[i] === arr[j]){
  7. arr.splice(j, 1);
  8. }
  9. }
  10. }
  11. }
  12.  
  13. var arr:Array = new Array("a", "b", "a", "c", "d", "b");
  14. removeDuplicate(arr);

URL: http://thinkdiff.net/flash-action-script-30/in-actionscript-3-how-to-remove-duplicates-from-array/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.