Return to Snippet

Revision: 24591
at March 4, 2010 15:51 by adrianparr


Initial Code
var array1:Array = new Array(1,2,3,4,5,6,7);
var array2:Array = new Array(1,2,3,9,5,6,7);

function checkIfArraysMatch($arrayA:Array, $arrayB:Array):Boolean 
{
	var isMatch:Boolean = true;
	if($arrayA.length == $arrayB.length) {
		for (var i:int = 0; i<$arrayA.length; i++) {
			if ($arrayA[i] != $arrayB[i]) {
				isMatch = false;
				break;
			}
		}
	} else {
		isMatch = false;
	}
	return isMatch;
}


trace(checkIfArraysMatch(array1, array2));

// OUTPUT: false

Initial URL

                                

Initial Description
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.

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

Initial Tags
array, copy

Initial Language
ActionScript 3