当前位置:网站首页>JS for loop number exception
JS for loop number exception
2022-07-05 11:56:00 【News777】
Error code
const res = await getList({
});
for(let i = 0;i < 5 - res.data.list.length;i++){
res.data.list.push({
day : new Date(),
name : 'xxx'
})
}
The reason for the error
demand :res.data.list Arrays satisfy length === 5
reason : Although variable res use const Statement , But because it is an object , It does not affect the change of attribute value in the object , because res.data.list constantly push, So it's length It's changing , Therefore, the number of cycles keeps decreasing ,res.data.list.length The length of did not meet expectations
solve
const res = await getList({
});
const len = res.data.list.length // increase
for(let i = 0;i < 5 - len;i++){
// change
res.data.list.push({
day : new Date(),
name : 'xxx'
})
}
边栏推荐
- pytorch-线性回归
- 一次生产环境redis内存占用居高不下问题排查
- yolov5目标检测神经网络——损失函数计算原理
- Sentinel sentinel mechanism of master automatic election in redis master-slave
- [upsampling method opencv interpolation]
- Solve readobjectstart: expect {or N, but found n, error found in 1 byte of
- [LeetCode] Wildcard Matching 外卡匹配
- 【 YOLOv3中Loss部分计算】
- Redis集群的重定向
- 【yolov5.yaml解析】
猜你喜欢
随机推荐
【load dataset】
Open3d mesh (surface) coloring
1. Laravel creation project of PHP
Linux安装部署LAMP(Apache+MySQL+PHP)
[untitled]
Project summary notes series wstax kt session2 code analysis
Troubleshooting of high memory usage of redis in a production environment
View all processes of multiple machines
Multi table operation - Auto Association query
COMSOL -- three-dimensional graphics random drawing -- rotation
[singleshotmultiboxdetector (SSD, single step multi frame target detection)]
The most comprehensive new database in the whole network, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, flying Book Multidimensional table, heipayun, Zhix
多表操作-子查询
1个插件搞定网页中的广告
Dynamic SQL of ibatis
Install esxi 6.0 interactively
Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
XML解析
【pytorch 修改预训练模型:实测加载预训练模型与模型随机初始化差别不大】
[crawler] bugs encountered by wasm
![[calculation of loss in yolov3]](/img/8c/1ad99b8fc1c5490f70dc81e1e5c27e.png)







![[crawler] bugs encountered by wasm](/img/29/6782bda4c149b7b2b334238936e211.png)