a multidimensional array is an array of arrays
just declare an array, then fill it with the x arrays inside, each with y elements.
To keep the same style as your provided code, you can do something like this
function a(x, y){
var myArray = [];
for(var i = 0; i < x; i++){
myArray[i] = [];
for(var j = 0; j < y; j++){
myArray[i][j] = 0;
}
}
return myArray;
}
var exampleArray = a(3,4);
console.log(exampleArray);
I wrote it like your snippet of code for understanding. However, there are better ways ('clearer' and probably more efficient, and more 'javascriptish') to write arrays. For example, see Ele's answer.
this.array[x][y];is supposed to do? can you elaboratethis.array = Array.from({length: x}, () => Array(y).fill(0))