当前位置:网站首页>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);
}
});
边栏推荐
- 国产钡铼分布式IO模块如何与西门子PLC Profinet通讯
- Analyst: Baidu could become China's most valuable company by 2030
- 谈谈如何建立价值驱动的数据战略
- Web APIs DOM- 网页特效篇 综合案例
- 160亿美元!传微软计划收购全球最大语音识别公司
- 【运维】ssh tunneling 依靠ssh的22端口实现访问远程服务器的接口服务
- FPGA设计16位二进制全加器模块
- 腾讯开源摘星计划培养开源贡献者的实践思考
- 要卖课、要带货,知识付费系统帮你一步搞定!
- In the Chinese ToB market, it is too difficult to choose the right supplier
猜你喜欢

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

Thread、Runnable、Callable、Future ... 的关系?

平行坐标图:高维数据可视化必备图形

One's deceased father grind English vocabulary training camp Day 】 16 - bankrupt, remain, regulate, the construct and reflect
![[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

500强企业如何提升研发效能?来看看行业专家怎么说

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

算力顶天地,存力纳乾坤:国家超级计算济南中心的一体两面

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

2022开放原子全球开源峰会OpenAnolis分论坛圆满落幕
随机推荐
KubeMeet 报名 | 「边缘原生」线上技术沙龙完整议程公布!
公司无线规划设计及实施SOP
In the Chinese ToB market, it is too difficult to choose the right supplier
kubernetes之资源限制及QOS服务质量
5年迭代5次,抖音推荐系统演进历程
[Code Hoof Set Novice Village 600 Questions] Given an integer n, find all the values of x and y in floor(n/x)=y
恐造成下一个“千年虫”的闰秒,遭科技巨头们联合抵制
【码蹄集新手村600题】给定一个整数n,求floor(n/x)=y 中 x,y 的所有值
500强企业如何提升研发效能?来看看行业专家怎么说
[Code Hoof Set Novice Village 600 Questions] Detailed explanation of pow() function
【Harmony OS】【ARK UI】ets使用第三方类库crypto实现加密解密
美国再度打压中国超算!申威、飞腾等7家实体被制裁
pfSense高可用(HA)功能介绍
虚拟偶像的歌声原来是这样生成的!
scroll bar style
FPGA设计16位二进制全加器模块
怎么样的框架对于开发者是友好的?
Blender 源码分析(2)
KubeZoo:字节跳动轻量级多租户开源解决方案
分批数据遍历的优化