2 Replies Latest reply on Sep 2, 2013 9:42 AM by Aaron Beall

    Array Collection Compare


      Hi ,


      Question - I want to compare 2 array collection and remove the objects from the arraycollection for example ,


      arr and arr1 are two arraycollection .








      ----------------------------------------------------------------------------------------- -----------------------






      I want if arr1 conatins the rLocalOwner=''' then id of that arr1 should remove that element from the arr,


      In this case arr should remove the element at index 0,1,3 becasue arr1 contains the null for the rLocalOwner, how can I achieve that


      I thought one way of for loop inside another for loop but I think this is performance degradation is there any another way ?




        • 1. Re: Array Collection Compare
          pauland Level 4

          First of all an empty string is not the same as null.


          You should use two loops in case the contents of the arrays aren't in the same order.

          • 2. Re: Array Collection Compare
            Aaron Beall Level 3

            This function does what you describe, against array instead of array collection:



            function compare(source:Array, filter:Array):void {
                      // loop end to front so splicing doesn't change index
                      sourceLoop: for(var i:int = source.length; i--; ){
                                var obj:Object = source[i];
                                // loop through the filter array to find the matching object
                                for each(var f:Object in filter){
                                          if(f.id == obj.id){
                                                              // if the filtered object has no local owner, 
                                                              // remove it from the source array
                                                              source.splice(i, 1);
                                                    continue sourceLoop;


            You should be able to adapt to array collection by replacing Array/splice() with ArrayCollection/removeItemAt()


            You could also look into using the ArrayCollection's filterFunction