Hi forum,
I was wondering what is the best way to create a multidimensional array in javascript. I have read in the documentation that if you want to create an array you should use the following sintaxis:
Example of an array of integers:
arrayName: {
default: [],
type: [cc.Integer]
}
This is working but I am not quite sure about how to create a multidimensional one. Could you please help?
I have tried to this way but it seems it is not working if the print in the consola playerCard[1,1] for example it prints “undefined”:
//Create 2d array
var playerCard = [];
for(i = 0; i <= 3; i++){
playerCard[i] = [];
};
//Initialize 2d array
for(i = 0; i <= 3; i++){
for(j = 0; j <= 3; j++){
playerCard[i][j] = 0;
};
};
console.log(playerCard[1][1]);
Thanks in advance and best regards,