I assume that you have initialized the array links someplace else, because I don't see it here. The way in which you are trying to assign values (for the first time) for the multidimensional array is incorrect. Each element inside the array isn't defined as a sub-array at first. Solved this problem using a simple for loop that iterates over the first 5 variables (in this case) and assigns them as empty variables. This can also be made dynamic depending on the nature of the problem.
Oh and lastly, you combined a return statement with an assignment statement. That's incorrect.
Check this link for more information.
dayCountTest = 0;
links = []; // declaring the array
for (var i = 0; i < 5; i++) {
links[i] = [,,,,,]; // making the first 5 elements of the link array as empty arrays of 6 length as there are six periods in this case
}
while (dayCountTest<5){
console.log("2");
if (dayCountTest == "0") {
tempDay = "Monday";
} else if (dayCountTest === "1") {
tempDay = "Tuesday";
} else if (dayCountTest == "2") {
tempDay = "Wednesday";
} else if (dayCountTest == "3") {
tempDay = "Thursday";
} else if (dayCountTest == "4") {
tempDay = "Friday";
}
periodCount = 0;
while (periodCount < 6) {
console.log("3");
let db = new sqlite.Database('./linksdb.db', sqlite.OPEN_READWRITE | sqlite.OPEN_CREATE);
let sql = `SELECT Link FROM `+ tempDay+`
WHERE Period = `+ periodCount + ``;
db.all(sql, [], (err, rows) => {
if (err) {
throw err;
}
rows.forEach((row) => {
links[dayCountTest][periodCount] = row.Link;
});
});
db.close();
periodCount++;
}
dayCountTest++;
This fix should get this code working right. Do let me know the outcome of this.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…