Remove redundant items from an array | ActionScript 3.0 AS3
Published by Nicholas Dunbar on December 24th, 2012
The following code is an example of how to remove redundant elements from an Array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var foundIndex:int; | |
if (theArray && theArray.length > 0){ | |
var len:int = theArray.length; | |
for (var i:int; i < len; i++){ | |
if (i+1 < len){ | |
foundIndex = theArray.indexOf(theArray[i], i+1); | |
} else { | |
foundIndex = -1; | |
} | |
if (foundIndex == -1){ | |
//not redundant | |
} else { | |
theArray.splice(i,1); | |
i--; | |
len--; | |
} | |
} | |
} |