2 Replies Latest reply on Jul 9, 2009 6:51 PM by kglad

    removing duplicate objects in array?

    shintashi Level 1

      This doesn't work at all.

       

      function removeDuplicates(a:Array):Array{
      for(var i=a.length-1;i>=0;i--){
      for(var j=i-1;j>=0;j--){
      if(a[i]==a[j]){
      a.splice(i,1);
      break;
      }
      }
      }
      return a;
      }

       

       

       

      my aPeople array consists of objects:


      function createfile(person){
          person = new Object();
              person.name = newname;
              person.age = newage;
      filename.text = person.name;
      fileage.text = person.age;
      aPeople.push(person);
      }

       

      savefile.onRelease = function(){
              thename = newname.text;
              createfile(thename);
          }

       

       

       

      but adding "removeDuplicates(aPeople);" after "createfile(thename);" has no effect: in other words, when I push the savefile button, it keeps creating clones of the same objects. What can I do?