当前位置:网站首页>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);
}
});
边栏推荐
猜你喜欢
[Operation and maintenance] ssh tunneling relies on the 22 port of ssh to realize the interface service of accessing the remote server
多线程并发Callable
In the Chinese ToB market, it is too difficult to choose the right supplier
工业软件上云的矛与盾
平行坐标图:高维数据可视化必备图形
EasyNVR更新版本至(V5.3.0)后页面不显示通道配置该如何解决?
北汇信息继续扩大V2X测试服务,扎根重庆,服务全国
Pagination with LIMIT
Dialogue with Academician Yu Fei of the Canadian Academy of Engineering: Looking for "Shannon's Theorem" in the field of AI
数据监控体系是什么?该怎么搭建?
随机推荐
AI 通过了图灵测试,科学家反应冷淡:“很棒,但没必要”
transformer通俗理解
维信诺与荣耀终端已签署8.91亿元订单
数据监控体系是什么?该怎么搭建?
Zadig 环境负载均衡:0 人工干预,极速部署
【码蹄集新手村600题】pow()函数详解
实时数仓:咸鱼的实时数仓经验分享
白宫将举办半导体产业链CEO峰会,台积电、三星、格芯、英特尔等将参与
解决 @RefreshScope 导致定时任务注解 @Scheduled 失效
多线程并发Callable
tar命令详解---归档及压缩
原理银行一直在收我利息!!!
The structure of the earth's over 200 million proteins is fully predicted, and AlphaFold detonates the "protein universe"
罚款182.28亿元!市场监管总局针对阿里巴巴垄断行为做出行政处罚
MySQL数据库的七种约束语法格式和使用详解&约束的总结
请问一下,我这个调度任务显示执行成功,但是并没有成功,我这个任务是odps sql ins
AMD收购赛灵思已获两家公司股东同意
为什么你的分布式数据中心需要一个全栈智能运维平台?
KubeZoo:字节跳动轻量级多租户开源解决方案
[Operation and maintenance] ssh tunneling relies on the 22 port of ssh to realize the interface service of accessing the remote server