A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: How can i delete Duplicates in an Array ?

  1. #1
    Member
    Join Date
    Jul 2002
    Posts
    50

    How can i delete Duplicates in an Array ?

    Hi !!!

    I was hoping someone could spare me a minute and help me with the problem im having. Probably a no-brainer, but unfortunately thats my problem..no brain

    Ive populated an array with some data from sql, and would love to delete all the duplicates...etc:

    [0] = 11111
    [1] = 11111
    [2] = 22222
    [3] = 22222
    [4] = 33333

    Ive tried all sorts of things to no avail, anyone got any ideas ?

    Many many thanks,
    Loomy

  2. #2
    Uses MX 2004 Pro Quixx's Avatar
    Join Date
    Nov 2004
    Location
    U.S.
    Posts
    877
    Hi,
    Maybe something like this will do the trick...

    Code:
    var a:Array = [1111, 5555, 1111, 3333, 1111, 3333, 6666, 2222, 2222, 4444];
    for (var i in a) {
    	for (var j in a) {
    		if (a[i] == a[j] and i != j) {
    			a.splice(Number(j), 1);
    		}
    	}
    }
    trace(a);

  3. #3
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Hi,

    Here is another option....

    Remove duplicates...
    code:

    things = ['Rock', 'Door', 'Stone', 'Door', 'Car', 'Dog'];
    temp = {};
    for (var i in things) {
    temp[things[i]] = 1;
    }
    things = [];
    for (var i in temp) {
    things.push(i);
    }
    trace(things);


  4. #4
    Member
    Join Date
    Jul 2002
    Posts
    50
    Thanks a million peeps !!! really appreciate it gonna try em both out

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center