# How to check if value exists in 2D array

Lets say I have a 2D array of objects. How does one check to see if an object exists in the 2D array without looping. I don’t know if 2D arrays allow me to do so, nor do I know if it has a function such as Exists() or Contains().

var x = 2;
var y = 3;
var allObjects = new GameObject[x,y];
for (var a = 0; a < x; a++) {
for (var b = 0; b < y; b++) {
// Assign objects to 2D array
allObjects[a,b] = ...;
}
}

// I get this message: RankException: Only single dimension arrays are supported.
if (object in allObjects) {
print('Hi! I'm in here!');
} else {
print("You've got the wrong object!");
}

Probably, it is necessary to write the function of check. Can there were small errors as I program on CSharp:

private var allObjects:GameObject[ , ] = null;

function Start() {
var x = 2;
var y = 3;
allObjects = new GameObject[x,y];
for (var a = 0; a < x; a++) {
for (var b = 0; b < y; b++) {
// Assign objects to 2D array
allObjects[a,b] = ...;
}
}
...
var mygmo: GameObject =...; //any object
if (checkArr(mygmo)) {
print("Hi! I'm in here!");
} else {
print("You've got the wrong object!");
}
}

//Function for checks object in array
function checkArr(gmo: GameObject): boolean {
for(var i:int = 0; i <= allObjects.GetUpperBound(0); i++) {
for(var j:int = 0; j <= allObjects.GetUpperBound(1); j++) {
if (gmo == allObjects[i, j]) {
return true;
}
}
}
return false;
}

Or maybe create check function with foreach(CSharp) from msdn help:

function checkArr(gmo: GameObject): boolean {
for(var i: GameObject in allObjects) {
if (gmo == i) {
return true;
}
}
return false;
}