当前位置:网站首页>for key in object 遍历对象遇到的问题
for key in object 遍历对象遇到的问题
2022-07-29 17:53:00 【weixin_46787337】
要遍历的对象
const [processBar, setProcessBar] = useState<{
[key: string]: {
loaded: number; total: number };
}>({
xxx: {
loaded: 222; total: 2222},
yyy: {
loaded: 222; total: 2222},
zzz: {
loaded: 222; total: 2222},
});
下面代码会报错
for(const item in processBar){
if (processBar.hasOwnProperty.call(processBar, item)) {
return ((processBar[item].loaded / processBar[item].total) * 100 || 0);
}
}
The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.(guard-for-in)
error 'body of a for in should be wrapped in an if statement' mean?
for key in object 遍历对象解决报错
Object.keys(processBar).map((item) => {
if (processBar.hasOwnProperty.call(processBar, item)) {
return ((processBar[item].loaded / processBar[item].total) * 100 || 0);
}
});
边栏推荐
- 开放原子开源基金会秘书长孙文龙:要打造以开发者为本的开源服务平台
- Dialogue with Academician Yu Fei of the Canadian Academy of Engineering: Looking for "Shannon's Theorem" in the field of AI
- P4775 [NOI2018] Intelligence Center (Line Segment Tree Merging)
- Blender 源码解析(1)
- 500强企业研发效能提升课,今晚开课啦!
- 平行坐标图:高维数据可视化必备图形
- 利用 JMeter 压测上传和下载接口实战
- 【Mysql系列】01_查询+排序
- 商业智能BI为什么能在数字化时代成为企业的基础建设
- 最近很郁闷
猜你喜欢
![[Operation and maintenance] ssh tunneling relies on the 22 port of ssh to realize the interface service of accessing the remote server](/img/4a/7156470e8d96c7709001bac88e872c.png)
[Operation and maintenance] ssh tunneling relies on the 22 port of ssh to realize the interface service of accessing the remote server

GRE MGRE

【Mysql系列】01_查询+排序

十大企业数据安全优秀实践

整体系统地认识网络安全与发展

倒计时1天! | 明日9点,这场精彩的Web3盛宴不容错过

为什么你的分布式数据中心需要一个全栈智能运维平台?

虚拟偶像的歌声原来是这样生成的!

腾讯开源摘星计划培养开源贡献者的实践思考
![[Code Hoof Set Novice Village 600 Questions] Given an integer n, find all the values of x and y in floor(n/x)=y](/img/c4/7cf18fca07c8d6550cadea2c3c9db4.png)
[Code Hoof Set Novice Village 600 Questions] Given an integer n, find all the values of x and y in floor(n/x)=y
随机推荐
[memory] grandma's song
MySql解决GROUP BY出现的问题
联发科天玑2000最快Q3量产,4G基带芯片将拿下Apple Watch订单
2022开放原子全球开源峰会OpenAnolis分论坛圆满落幕
【MySQL】如何向mysql数据库插入当前时间
[Code Hoof Set Novice Village 600 Questions] Given an integer n, find all the values of x and y in floor(n/x)=y
【STM32CubeMX】STM32H743配置IAP升级
转载:同班毕业两夫妻退休待遇四比一
tar命令详解---归档及压缩
swin-transformer初步理解
mysql存储过程 实现全量同步数据并自动创建表
公司无线规划设计及实施SOP
分析师:百度到2030年可能成为中国市值最高的公司
国产钡铼分布式IO模块如何与西门子PLC Profinet通讯
【码蹄集新手村600题】给定一个整数n,求floor(n/x)=y 中 x,y 的所有值
软考高级软件架构风格定义以及分类
要卖课、要带货,知识付费系统帮你一步搞定!
整体系统地认识网络安全与发展
解决报错Unsupported field: HourOfDay
kubernetes之资源限制及QOS服务质量