"lene"(테스트 샘플)을 변수 "q"에 푸시하려고합니다. 웬일인지 내 브라우저에서 언급 한 내용입니다.JavaScript undefined는 함수가 아닙니다 (splice 함수 사용)
Javascript highscore.html:24 Uncaught TypeError: undefined is not a function
Javascript highscore.html:145 Uncaught TypeError: Cannot read property 'length' of undefined
첫 번째 오류로 인해 145 번째 줄에 오류가 있습니다. 여기에 의견에 24 행을 표시했습니다.
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
};
"[i]"를 제거하면 24 행이 작동합니다. 누구나 오류의 원인인지 및/또는 해결 방법을 알고 있습니까?
Q [I]과 동일
를 배열하지 않습니다. 너 뭐하려고? –
'i','DAY','d1i','d2i','days_passed1' 등을 어딘가에 선언 하시겠습니까? 왜냐하면 당신의 코드가 [* The Implicit Globals *]의 공포에 빠지기 때문입니다 (http://blog.niftysnippets.org/2008/03/horror-of-implicit-globals.html). –