当前位置:网站首页>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);
}
});
边栏推荐
- 593. 有效的正方形 改善丑陋的代码
- 62页智慧冷链产业园整体解决方案2022
- KubeZoo:字节跳动轻量级多租户开源解决方案
- 最近很郁闷
- 2022开放原子全球开源峰会OpenAnolis分论坛圆满落幕
- 字节跳动基于 Iceberg 的海量特征存储实践
- The structure of the earth's over 200 million proteins is fully predicted, and AlphaFold detonates the "protein universe"
- 有哪位大佬做成功oracle数据库cdc同步的啊,是不是必须是基表才会啊,视图是没用的吧
- turtle简单教程文档
- Mathematical Analysis_Proof_Two Important Limits (Tongji Version)
猜你喜欢

数据监控体系是什么?该怎么搭建?

KubeZoo:字节跳动轻量级多租户开源解决方案

多线程并发Callable
![[STM32CubeMX] STM32H743 configuration IAP upgrade](/img/4b/2445d6c9dd16d45c1ac7adddbf0ae6.png)
[STM32CubeMX] STM32H743 configuration IAP upgrade

Dialogue with Academician Yu Fei of the Canadian Academy of Engineering: Looking for "Shannon's Theorem" in the field of AI
![[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

RestTemplate源码debug:可变形参引发的问题

谈谈如何建立价值驱动的数据战略

One's deceased father grind English vocabulary training camp Day 】 16 - bankrupt, remain, regulate, the construct and reflect

支持向量机SVM
随机推荐
分批数据遍历的优化
【7.23-7.29】博客精彩回顾
Web APIs DOM- 网页特效篇 综合案例
【深度学习】使用yolov5对数据进行预标注
机器学习:知道模型评估中的SSE、“肘”部法、SC系数和CH系数的实现原理
7行代码让B站崩溃3小时,竟因“一个诡计多端的0”
MySql解决GROUP BY出现的问题
macro definition small method
数据监控体系是什么?该怎么搭建?
疫情之下,逆势成长的平板市场,究竟会不会是昙花一现?
深投控收购意大利半导体设备商被叫停
Blender 源码解析(1)
请问跑sql任务调度必须得设置依赖的上游节点嘛?比如说我sql里面a b两张表join出来的结果写入
[memory] grandma's song
工作9年了!
发力5G平板市场,品网科技首发展锐5G平板解决方案
[转帖]为什么收入越来越少?
有效供应链管理的八大绩效分析指标(下)
宏定义小方法
How different DAOs are changing the world