Access varibles in and array

How would I go about accessing a variable in an/multiple objects in an array. JS script

The game object Unit will be placed will be placed inside the seleectedUnits array. How would I get the variable targetLocation in Unit to equal movementOrders in Commander. There will be multiple Units inside the array.

Commander Script

var selectedUnits : Array = new Array();
var movementOrders : float;

Unit Script

var targetLocation : float;

Thanks

Don’t use new Array(), try this instead:

// Declare an empty array using array literal notation
var selectedUnits = [];

To access any element in the array, say the sixth element, do:

selectedUnits[6];

So for example if you wanted to save the sixth element of the array & print the value:

unitSix = selectedUnits[6];
Debug.log(unitSix);

Take a look at this tutorial for more info on arrays.