NewTerminator
Programmer
Anyone know how to remove duplicate values from an array using actionscript. Any help would be appreciated. Thanks..
NewTerminator
NewTerminator
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
removeDuplicates = function (checkArray) {
for (var i = 0; i<checkArray.length; i++) {
var k = i+1;
for (var j = k; j<checkArray.length; j++) {
if (checkArray[i] == checkArray[j]) {
checkArray.splice(j, 1);
}
}
}
return checkArray;
};
myArray = [1, 2, 3, 4, 5, 6, 7, 5, 4, 8, 9, 2, 3, 4, 1, 8, 9];
trace("before "+myArray);
myNewArray = removeDuplicates(myArray);
trace("after "+myNewArray);
//
stop();
aNumberList = new Array(1,2,3,4,5,5,2,1,4,3);
aNewArray = new Array();
for(i=0;i<aNumberList.length;i++){
bExists = false;
for(j=0;j<aNewArray.length;j++){
if(aNumberList[i] == aNewArray[j]){
bExists = true;
}
}
if(!bExists){
aNewArray[aNewArray.length] = aNumberList[i];
}
}
trace(aNewArray);
[code]
Regards,
[img]http://members.lamicro.com/~FGill/cubalibre2.gif[/img]