AS3 Check if All the Values in Two Different Arrays are the Same


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

I'm not sure whether I should be using == (Equality) or === (Strict equality) here. I haven't been able to create a situation where it makes much difference. If you know better, feel free to leave me a comment.


Copy this code and paste it in your HTML
  1. var array1:Array = new Array(1,2,3,4,5,6,7);
  2. var array2:Array = new Array(1,2,3,9,5,6,7);
  3.  
  4. function checkIfArraysMatch($arrayA:Array, $arrayB:Array):Boolean
  5. {
  6. var isMatch:Boolean = true;
  7. if($arrayA.length == $arrayB.length) {
  8. for (var i:int = 0; i<$arrayA.length; i++) {
  9. if ($arrayA[i] != $arrayB[i]) {
  10. isMatch = false;
  11. break;
  12. }
  13. }
  14. } else {
  15. isMatch = false;
  16. }
  17. return isMatch;
  18. }
  19.  
  20.  
  21. trace(checkIfArraysMatch(array1, array2));
  22.  
  23. // OUTPUT: false

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.