当前位置:网站首页>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);
}
});
边栏推荐
- Batch_Normalization 、Layer_Normalization 、Group_Normalization你分的清楚吗
- Blender 源码分析(2)
- 使用LIMIT分页
- 【考研英语词汇训练营】Day 16 —— bankrupt,remain,regulate,construct,reflect
- One's deceased father grind English vocabulary training camp Day 】 16 - bankrupt, remain, regulate, the construct and reflect
- 【Mysql系列】01_查询+排序
- 数学分析_证明_两个重要极限(同济版本)
- 云商店专访 | 云速ERP,小场景里帮企业做“大生意”
- The structure of the earth's over 200 million proteins is fully predicted, and AlphaFold detonates the "protein universe"
- 罚款182.28亿元!市场监管总局针对阿里巴巴垄断行为做出行政处罚
猜你喜欢
随机推荐
腾讯开源摘星计划培养开源贡献者的实践思考
Pagination with LIMIT
开放原子开源基金会为白金、黄金、白银捐赠人授牌,CSDN荣获黄金捐赠人
超声波传感器(CHx01) 学习笔记 Ⅲ-API介绍
[网络]WAN技术组播
宏定义小方法
三轮电摩专用之48V动力锂电池组-产品规格书
Virtink:更轻量的 Kubernetes 原生虚拟化管理引擎
本周投融报:CeFi积聚风投吸引力
字节跳动基于 Iceberg 的海量特征存储实践
P5514 [MtOI2019]永夜的报应(位运算)
HCIP笔记第十四天
转载:同班毕业两夫妻退休待遇四比一
This week's investment report: CeFi accumulates venture capital attraction
机器学习:知道模型评估中的SSE、“肘”部法、SC系数和CH系数的实现原理
kubernetes之资源限制及QOS服务质量
UG安装出现Server Start Failed. The Server May Already Be Running!!解决方法
AMD收购赛灵思已获两家公司股东同意
京东方Q1净利将超50亿!手机、电视等五大显示屏出货量全球第一
开放原子开源基金会秘书长孙文龙:要打造以开发者为本的开源服务平台








![[Code Hoof Set Novice Village 600 Questions] Detailed explanation of pow() function](/img/d7/c57caa31c16f2e8f7bcd0003cb2791.png)
