Get array values from other script

I have an array of game objects i set in a c# script .
later i need the array of objects in a different java script that is not attached to the same object as the c# script.
how can i get the array from one c script to the java script?

There are a few ways of doing this!

The first is to assign a known, unique tag to the object with the C# script on it (say “arrayObject”) and then use

var gameObjectArray : GameObject[] = GameObject.FindWithTag("arrayObject").
             GetComponent("nameOfC#Script").whateverYouCalledTheArray;

from any javascript component in the scene.

Another way to do it (a bit more specific) is to have a direct reference to the gameObject in question (instead of using FindWithTag)

so in your javascript-

var arrayObject : GameObject

/* whatever code*/

var gameObjectArray : GameObject[] = arrayObject.GetComponent("nameOfC#Script").
                                          whateverYouCalldTheArray;

There are a few other ways, but they become more and more complex, and require more and more coding knowledge to pull off.

A thing to remember, is that javascript objects cannot see C# scripts at compile time. They have to communicate through awkward lookups and messenger classes, which is not very efficient. If you absolutely must be using C# for one of your scripts, you should use it for all of them- it is much cleaner and easier that way. For example, it would be possible to refer to the script directly, instead of having to rely on gameObject.GetComponent().

Yet another thing- the arrays returned here are builtin arrays- not Unity’s ArrayList wrapper which is sometimes called the same thing. They are fixed-size, and don’t have any of the special functionality of the Array class.