help converting javascript this function

I’m trying to convert a few html/javascript array functions into unityscript for a statistics project in unity. This one is confusing me because they use the “this” keyword. It creates a 2 dimensional array. Any help rewriting this in unityscript would be appreciated…I just need help with the “this” line. Later there is a line that calls this using New. Like xy=new makeArray2(). I don’t think either of these are allowed in unityscript right?

function makeArray2 (X,Y)
        {  
        var count;  
        for (var count = 0; count < X; count++)  
                this[count] = new makeArray(Y);  
        }   
  
function makeArray (Y)  
        {  
        var count;  
        this.length = Y+1;  
        for (var count = 0; count <= Y+1; count++)  
                this[count] = 0;  
        }

As of 3.2, Unityscript has built-in support for multidimensional arrays. It looks like you’re creating a box shaped jagged array so a multi-dim array is slightly different, but it should be what you want:

var multiDimArray : int[x , y];

if you do need a jagged array, the best way to do them is to use this helper script. Unityscript has syntax for using them, but none for creating them so you need a C# script to create your instance.

Another technique that will work is to use js arrays. Its worth noting that js arrays aren’t as fast as .Net arrays so you should generally try and avoid them in Unity:

 var arrayOfArrays : Array;
 for (var i = 0 ; i < 6 ; i ++) {
       arrayOfArrays.Push( new Array(i) );
}
//Creates an array full of 6 more arrays each one unit longer than the previous.