Your function is fine if you want to only remove the 1st occurance of a repeat. 
However, 3 in a row will be only reduced to 2. I'm guessing that's what's 
happening to you.

In other words, [1,1,2,3,3,4] will properly reduce to [1,2,3,4] with your 
function. However, [1,1,1,2,3,3,4] will only reduce to [1,1,2,3,4].

Trace through your function using the above examples step by step and you 
should see where your error is.

Scott


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Allandt
Bik-Elliott (Receptacle)
Sent: Tuesday, May 22, 2007 1:05 PM
To: flashcoders
Subject: [Flashcoders] remove duplicate items in array


hi guys

i'm looking for a way of removing duplicate items in an array

i've done this so far

//sort array so all items of the same content are grouped together
myArray.sort();

//loop through items, removing any sitting next to a duplicate
for (var i:Number = 0; i < myArray.length; i++) {
        if (myArray[i] == myArray[i+1]) {
                myArray.splice (i, 1);
        }
}

however, i always seems to end up with the first 2 items in the array  
being the same (although it works well after that)

i can't figure out why - hope you can help

obie
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

______________________________________________________________________
This email has been scanned by MessageLabs Email Security System for spam, 
virus, and inappropriate content.
______________________________________________________________________
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to