I have a nested array and I want to update that array with values in my database. It is based on a timetable: a 5 day week with 6 periods in each day. Monday is 0 and Friday is 4 in the array. There is period 0 up until period 5. When I execute this function it says: Cannot Set property '6' is undefined And my array is not updated When I remove the "return" line, the error does not occur but obviously my array is still not updated. Is this due to having multiple returns due to the loop. And if so how do i fix this? If it's another error please show me! If there is anymore information need please ask!
dayCountTest = 0;
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) => {
return links[dayCountTest][periodCount] = row.Link;
});
});
db.close();
periodCount++;
}
dayCountTest++;
}
===(same type, same value, ergo no type coercion) and check a number type with a string type. this is alwaysfalse. please have a look to the various possibilities of checking a value in javascript.