I'm trying to push "lene"(its just a test sample) into the variable "q". For some reason this is what my browser mentions:
Javascript highscore.html:24 Uncaught TypeError: undefined is not a function
Javascript highscore.html:145 Uncaught TypeError: Cannot read property 'length' of undefined
The second error, on line 145 is a because of the first error. I have marked line 24 in the comments here:
var q = [{
TernRank: 2,
TernVan: '03/12/2014',
TernTot: '01/01/2015',
TernDagen: 1
}, {
TernRank: 3,
TernVan: '08/01/2014',
TernTot: '01/01/2015',
TernDagen: 1
}, {
TernRank: 1,
TernVan: '03/12/2014',
TernTot: '01/01/2015',
TernDagen: 1
}, {
TernRank: 4,
TernVan: '03/12/2014',
TernTot: '01/01/2015',
TernDagen: 1
}];
DAY = 1000 * 60 * 60 * 24
for (i = 0; i < 4; i++) {
d1i = new Date(q[i].TernVan)
d2i = new Date(q[i].TernTot)
days_passedi = Math.round((d2i.getTime() - d1i.getTime()) / DAY)
q[i].splice(3, 0, "Lene"); //This is line 24
};
The line 24 does works if I remove the "[i]". Does anyone know why it's causing the error or/and how to fix it?