Compare two array


/ Published in: ActionScript 3
Save to your folder(s)

Consider the following piece of code which compares two arrays to find which elements exist in outerArray that do not exist in innerArray:


Copy this code and paste it in your HTML
  1. var outerArray:Array = ["coffee", "juice", "water", "beer"];
  2. var innerArray:Array = ["liquor", "beer", "wine", "juice"];
  3.  
  4. for each (var foo:String in outerArray)
  5. {
  6. var found:Boolean = false;
  7. for each (var bar:String in innerArray)
  8. {
  9. if (foo == bar)
  10. {
  11. found = true;
  12. }
  13. }
  14. if (!found)
  15. {
  16. trace(foo);
  17. }
  18. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.