Can anyone help me with a system that helps me to access data inside of data?

I followed lessons on codeacademy in Javascript but they don’t seem to apply in Unity. What I would like to achieve is accessing data inside of data like to following example:

var array01 = [1,2,3,4];
var array02 = [5,6,7,8,9,10];
var arrayBoth = [array01, array02];

// I would like to acces data with one command like:


Can anyone help me with a system that helps me to access data inside of data?

codeacademy’s JavaScript tutorial is for Web JavaScript, which is not at all the same as Unity’s poorly named JavaScript, also sometimes referred to as “UnityScript” to clear the confusion. Their tutorial does not apply whatsoever to Unity, save perhaps superficial syntax familiarity.

You declare, instantiate and access arrays in UnityScript like so:

// Array declaration:
var arrayExample : int[];

// Array instantiation:
arrayExample = new int[10];

// Array access:
var fifthElement = arrayExample[5];

Example of rectangular array syntax in JS:

// Declaration of rectangular array:
var rectArray : int[,];

// Instantiate the rectangular array
rectArray = new int[3,3];

// Set the value of an element inside the array (at column = 2, row = 2) to 10
rectArray[2,2] = 10;

// Access the element at that position again and store it in a local variable:
var twoPointTwo = rectArray[2,2];

Debug.Log("Value of element at 2,2: " + twoPointTwo);

Thanks for the fast reply! however It still doesn’t work for me. I tried your code inside of Unity and both Debug.Log’s don’t output what I want(number 2).

var arrayExample : int[];

arrayExample = new int[3];
arrayExample = new int[2];

var secondElement = arrayExample[1];


The classic javascript way allows me to acces single items of the array. (I’m sure that it can be done with your way two). But what I really want is to access data that is inside a array in a array(see my example on top) Hope this make sence!