js报错- cannot set property xxx of undefined
case1
报错代码
quizList[index] = currentQuiz;
quizList[index].learningItem = item;
报错内容
Cannot read properties of undefined (reading 'learningItem')
报错原因
currentQuiz对象有可能是undefined,如果再给undefined对象quizList[index]动态添加属性learningItem,会导致出现cannot set property xxx of undefined报错
解决方法
quizList[index] = currentQuiz == undefined ? {} : currentQuiz;
quizList[index].learningItem = item;
判断一下quizList[index]是否是undefined即可
case2
报错代码
quiz.finishedstudent.forEach(item => {if (item.score < 80) {errorNum++;}
})
报错内容
Cannot read properties of undefined (reading 'forEach')
解决方法
if (quiz.finishedstudent != undefined) {quiz.finishedstudent.forEach(item => {if (item.score < 80) {errorNum++;}})
}
js报错- cannot set property xxx of undefined相关推荐
- vue echarts使用map地图 引入china.js报错Cannot read property ‘echarts’ of undefined
下载china.js导入项目中引入,会报错Cannot read property 'echarts' of undefined import Echarts from "echarts&q ...
- 事件监听一直报错Cannot set property 'display' of undefined
为什么80%的码农都做不了架构师?>>> css ↓ .wechatBtn {position: relative;} .wechat {position: absolute; ...
- Vue开启Gzip打包异常:webpack打包报错Cannot read property ‘emit‘ of undefined
Vue开启Gzip打包异常:webpack打包报错Cannot read property 'emit' of undefined 相关代码 const CompressionPlugin = req ...
- vue 报错 Cannot read property ‘__ob__‘ of undefined的解决方法
vue 报错 Cannot read property '__ob__' of undefined的解决方法 参考文章: (1)vue 报错 Cannot read property '__ob__' ...
- DateTimePicker 日期时间选择器报错 Cannot read property ‘getHours‘ of undefined, 无法选中`[__ob_: observer__]`时做判断
我在一次开发中遇到了这个情况:使用DateTimePicker 日期时间选择器,出现无法选中, 报错 Cannot read property 'getHours' of undefined, 这个原 ...
- uniapp 小程序报错 Cannot read property ‘forceUpdate‘ of undefined
uniapp 小程序报错 Cannot read property 'forceUpdate' of undefined 1.问题: 解决:配置小程序的ID manifest.json的文件
- vue 报错 Cannot read property ‘_wrapper‘ of undefined
vue项目中,使用了各种插件和ui库,有时候会出现 Cannot read property '_wrapper' of undefined 这样的报错,一开始还以为是引用的插件报错, 其实是自定义 ...
- 微信小程序接入百度统计报错 Cannot read property ‘mtj‘ of undefined
参考文章微信小程序如何接入百度统计并且自定义事件分析_improvement-CSDN博客_百度统计 自定义事件 接入百度统计,遇到了几个坑 1.第一个坑--微信小程序后台配置了https://hmm ...
- cesium CLAMP_TO_GROUND 报错 Cannot read property ‘globe‘ of undefined
billboardCollection 需要添加heightReference: Cesium.HeightReference.CLAMP_TO_GROUND var viewer = new Ces ...
最新文章
- 人工智能都沸腾3年了,现在就业情况还乐观吗?
- 偏移出来的数据不准_独家解读!京东高可用分布式流数据存储的架构设计
- java如何得到GET和POST请求URL和参数列表(转)
- elasticsearch 客户端工具_ELK集群部署 - elasticsearch-7.9.3
- 性能测试工具比较:LoadRunner vs JMeter - 测试结果数据比较
- Qt|OpenGL学习笔记-绕X轴、Y轴、以及XY轴旋转的四边体
- 加密解密技术基础、PKI及创建私有CA
- 远古有圆孔的头颅可能是穿越者
- Java面向对象编程,绘制思维导图(全面详细整理)
- 警务综合平台情报研判应用建设方案
- java读取文件 classpath_Java读取Classpath文件
- FEC(前向纠错码)
- WordPress站点被挂马,如何预防、检测和应对?
- 一、数据库之理论基础
- 我的世界java版粘土服务器ip,clay黏土服务器下载
- 世界非著名的十大奇迹
- 百度ueditor编辑器如何使用自定义的高大上高亮皮肤?
- SpringSecurity整合springBoot、redis——实现登录互踢
- 海鲜吃得好,喝酒少不了,盒马痛风套餐来了
- 2022年3月青少年机器人技术等级考试理论综合试卷(一级)
热门文章
- 英创力电子IPO被终止:年营收10亿 深创投与红土是股东
- python什么是调用_什么是Python中的可调用?
- ACM知识竞)赛 之 SDUT3034 炸学校(最短路Dijkstra)
- 中国欲量产AI人才,本科招生爆发后如何培养?
- 两台计算机怎么快速拷贝文件夹,两台电脑,用什么方法相互传文件最快?
- 简述C语言中32个关键字
- db4o_8.0对象数据库官方文档翻译_学习笔记三
- PyautoGui 常用教程(一篇就够)
- egg html模板,egg+vue服务端渲染模板项目介绍
- egg-sequelize使用教程