Skip navigation
Currently Being Moderated

Compare arrays

Jul 28, 2009 10:37 PM

Is there any simple way to compare two arrays.

 

ie; I have two arrays  (a,b,c,d,e) and (b,c,d) after comparison I would like to get an array (a,e).

 
Replies
  • Currently Being Moderated
    Jul 29, 2009 4:53 AM   in reply to webqaflash

    Could you clarify the requirements for the comparison?  Don't answer for each of these, but instead define the criteria that covers all of them for the results you would want...

     

    What if you have  (b,c,d) and (a,b,c,d,e)?

     

    What if you have  (a,b,c,d,e) and (z,b,c,d,x)?

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 29, 2009 5:25 AM   in reply to webqaflash

    This is one way...

     

    var array1:Array = new Array("a","b","c","d","e");
    var array2:Array = new Array("b","c","d");


    var array3:Array = new Array();

     

    for(var i:uint=0; i<array1.length; i++){
          if(array2.indexOf(array1[i]) == -1){
                array3.push(array1[i]);
          }
    }

     

    trace(array3);

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 29, 2009 6:02 AM   in reply to webqaflash

    You're welcome

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 19, 2012 2:04 PM   in reply to Ned Murphy

    Thanks a ton!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points