case1
Error code
quizList[index] = currentQuiz;
quizList[index].learningItem = item;
Error content
Cannot read properties of undefined (reading 'learningItem')
Error reporting reason
currentQuiz object may be undefined, if you add the property learningItem to the undefined object quizList[index] dynamically, it will cause the error “cannot set property xxx of undefined”.
Solution:
quizList[index] = currentQuiz == undefined ?{} : currentQuiz;
quizList[index].learningItem = item;
Just judge whether the quizlist [index] is undefined
case2
Error code
quiz.finishedstudent.forEach(item => {
if (item.score < 80) {
errorNum++;
}
})
Error content
Cannot read properties of undefined (reading 'forEach')
Solution:
if (quiz.finishedstudent != undefined) {
quiz.finishedstudent.forEach(item => {
if (item.score < 80) {
errorNum++;
}
})
}
Read More:
- [Solved] Syntax Error: TypeError: Cannot set property ‘parent‘ of undefined
- [Solved] Binding onclick event in JS: for loop: error uncaught typeerror: cannot set properties of undefined (setting ‘classname’)
- [Solved] Vue element UI form verification error: cannot read property ‘validate’ of undefined
- Uni-app Error when assigning a value to a component: [system] TypeError: Cannot read property ‘name‘ of undefined
- Vue cannot read property ‘xxx’ of undefined solutions
- Cannot read property ‘isFile‘ of undefined [How to Solve]
- [Solved] Cannot read property ‘setCheckedKeys‘ of undefined“
- [Solved] HBuilder Error: Cannot read property ‘forceUpdate‘ of undefined
- [Solved] Syntax Error: TypeError: Cannot read property ‘parseComponent‘ of undefined
- [Solved] electron Error: Uncaught TypeError: Cannot read property ‘BrowserWindow‘ of undefined
- [Solved] TYPEERROR: CANNOT READ PROPERTY ‘REDUCE‘ OF UNDEFINED
- [Solved] vue.esm.js?efeb:591 [Vue warn]: Error in event handler for “click“: “TypeError: Cannot read property
- [Solved] Vue Error: TypeError: Cannot read property ‘end‘ of undefined
- [Solved] Syntax Error: TypeError: Cannot read property ‘parseComponent‘ of undefined
- [Solved] Element form method resetfields() error: vue.runtime.esm.js?2b0e:1888 TypeError: Cannot read properties of undefined (reading ‘indexOf’)
- [Solved] JS Error: Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML‘)
- JS bug Log Uncaught TypeError: Cannot read property ‘previoustSibling‘ of null
- [Solved] Echarts Error: Cannot read property ‘init‘ of undefined
- [Solved] Install The Latest Version of Jest Error: TypeError: Cannot read property ‘instrument‘ of undefined
- Method to solve uncaught typeerror: cannot set property ‘onclick’ of null error