我试图在javascript中创建2个二维数组作为全局变量,如下所示:
player = [nPlayers];
helps = [nPlayers];
我将它们填入for
循环中,如下所示:
for (i = 0; i < nPlayers; i++) {
j = i + 1;
name = window.localStorage.getItem('player' + j);
player[i] = [j, name, 0];
helps[i] = [1,1,1,1];
直到这里,一切都很好,但每次我做这样的事情:
var currentPlayer = 1;
player[currentPlayer][2];
它给了我这个错误:
Uncaught TypeError: Cannot read property '0' of undefined
有人可以帮我吗?