Array of GameObjects, accessing them through a for loop

Hey there unity answers

What I have set up in my script is that, I create one of 4 cube prefabs, and add it to an array called arrayCube. I need to add them one by one to ensure I can rely on the order. I am currently, not accessing them correctly, and would like to... here's a snip of code: Each gameObject living in this array has a int var on it called idNumber... this is a portion of a condition I'd like to check

static var arrayCube = new Array();

for(i=0; i < 120; i++){
     if(arrayCube*.idNumber == arrayCube[i+1].idNumber){*
 *doThisStuff;*
 *}*
*}*
*```*
*<p>My end goal is to test if variables on nearby objects in this array are the same.  Any tips on doing this in a smarter way (I'm sure there's millions) let me have em! </p>*
*<p>If you need any more info from me, let me know!</p>*

You use the Array class. Builtin native .Net arrays would be much faster but not as flexible as the Array class. Builtin arrays can't be resized once they are created. Since i don't know how you add your objects to your array i guess you will keep your Array-class array.

Here an example of storing the reference to an attached script rather than the GameObject reference.

var prefab : GameObject;

function CreateObject()
{
    var newObject : GameObject = Instantiate(prefab);
    var script : CubeScript = newObject.GetComponent.<CubeScript>();
    arrayCube.Add(script);
}

In this example my prefabs would have a script attached that is called "CubeScript". The array stores the reference to those scripts on the GOs. Now you can easy access a variable in the script:

if(arrayCube*.idNumber == arrayCube[i+1].idNumber)*
*```*
*<p>If you need now access to the GO the script is attached to just use:</p>*
*```*
_arrayCube*.gameObject*_
_*```*_
_*<p>Every <a href="http://unity3d.com/support/documentation/ScriptReference/Component.html" rel="nofollow">component</a> (including <a href="http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.html" rel="nofollow">MonoBehaviour</a>) have <a href="http://unity3d.com/support/documentation/ScriptReference/Component-gameObject.html" rel="nofollow">this property</a> to access the owning GO.</p>*_
_*<p>ps. Use typed variables like i did above. They are much faster and saver. The compiler will be able to find type-mismatch errors which otherwise you get at runtime. I prefer C# because the code looks cleaner to me ;). But if you're happy with JS, keep it.</p>*_