JavaScript Array [i]未定义

时间:2016-02-26 23:17:48

标签: javascript jquery arrays

我将在javascript中使用此代码

Players = [
    ["івлавіл", 0, "PersonId0"],
    ["івлавіл", 0, "PersonId1"],
    ["івлавіл", 0, "PersonId2"]
];

var boys = 0,
    girls = 0,
    counter = 0,
    ip,
    PlayersCount = Players.length;

for (ip = 0; ip < PlayersCount+1; ip++) {
    if (Players[ip][1] == 0) {
        boys++;
    }
    else if (Players[ip][1] == 1) {
        girls++;
    }
};

当我运行这个时,我有这个错误“TypeError:Players [ip] is undefined”。

2 个答案:

答案 0 :(得分:2)

ip < PlayersCount+1

摆脱+1。你正试图从数组中读取一个额外的项目。

答案 1 :(得分:0)

我单独调试此错误;

我需要改变

CONVERT(DATETIME, EXPDATE) CONVERT(DATETIME, EXPDATE, 102) (CONVERT(DATETIME, CAST(EXPDATE AS CHAR(8)), 112)) CONVERT(DATETIME, CAST(expdate AS VARCHAR(8)))

for(ip = 0; ip < PlayersCount+1; ip++)