当前位置:网站首页>For key in object traversal of objects encountered problems
For key in object traversal of objects encountered problems
2022-07-29 19:02: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 Traverse the object to solve the error
Object.keys(processBar).map((item) => {
if (processBar.hasOwnProperty.call(processBar, item)) {
return ((processBar[item].loaded / processBar[item].total) * 100 || 0);
}
});
边栏推荐
猜你喜欢

Virtink:更轻量的 Kubernetes 原生虚拟化管理引擎

【Harmony OS】【ARK UI】ets使用第三方类库crypto实现加密解密

商业智能BI为什么能在数字化时代成为企业的基础建设

公司无线规划设计及实施SOP

String类型_static成员_动态内存分配_拷贝构造函数_const关键字_友元函数与友元类

7行代码让B站崩溃3小时,竟因“一个诡计多端的0”

11.99万起,东风风行游艇上市,产品力越级诚意满满

滚动条样式

This week's investment report: CeFi accumulates venture capital attraction

【码蹄集新手村600题】给定一个整数n,求floor(n/x)=y 中 x,y 的所有值
随机推荐
sticky定位后设置right:0不生效
新王加冕还是动物乐园?7大顶级蓝筹NFT项目详解
MySQL数据库的七种约束语法格式和使用详解&约束的总结
国产钡铼分布式IO模块如何与西门子PLC Profinet通讯
UG安装出现Server Start Failed. The Server May Already Be Running!!解决方法
A redis tool class to solve cache breakdown, cache penetration
KubeZoo:字节跳动轻量级多租户开源解决方案
for key in object 遍历对象遇到的问题
平行坐标图:高维数据可视化必备图形
HCIP笔记第十四天
Zigbee组网控制流程
[memory] grandma's song
RestTemplate源码debug:可变形参引发的问题
[STM32CubeMX] STM32H743 configuration IAP upgrade
ARTS-第-25-期
Web APIs DOM- 网页特效篇 综合案例
[转帖]为什么收入越来越少?
Network Effects in Web3
十大企业数据安全优秀实践
P4775 [NOI2018] 情报中心(线段树合并)