Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays 1

Status
Not open for further replies.

Brian56

Programmer
May 29, 2003
66
CA
Hi,

I have an array that is initially populated from a database. The user can also search the database and this will lead to the array being updated.

Everythings works fine up to this point except that the array can now contain duplicate values. I need to check the array for duplicate values and if a dupicate is found it must be deleted as otherwise this can sometimes and unpredictably cause the wrong information to be displayed.

I haved searched the actionscript dictionary and cannot find a command that will let me do this.

Can someone please point me down the road I need to go?
 
There's nothing built in to the array object but this script will do what you're after:

Code:
testArray = [12, 34, 56, 78, 90, 43, 43, 65, 87, 98, 32, 12, 44, 90, 63];
//
trace('initial array values '+testArray);
//
for (init=0; init<testArray.length; init++) {
	for (i=init+1; i<testArray.length; i++) {
		if (testArray[init] == testArray[i]) {
			trace(&quot;duplicate number found: &quot;+testArray[i]);
			testArray.splice(i, 1);
		}
	}
}
//
trace('final array values '+testArray);
 
Thank you very much !!! Problem solved.

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top