当前位置:网站首页>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'
})
}
边栏推荐
猜你喜欢
13. (map data) conversion between Baidu coordinate (bd09), national survey of China coordinate (Mars coordinate, gcj02), and WGS84 coordinate system
调查显示传统数据安全工具在60%情况下无法抵御勒索软件攻击
无线WIFI学习型8路发射遥控模块
[yolov5.yaml parsing]
Mongodb replica set
splunk配置163邮箱告警
[crawler] Charles unknown error
pytorch-softmax回归
How to protect user privacy without password authentication?
[mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]
随机推荐
Unity Xlua MonoProxy Mono代理类
[pytorch modifies the pre training model: there is little difference between the measured loading pre training model and the random initialization of the model]
15 methods in "understand series after reading" teach you to play with strings
C operation XML file
Halcon 模板匹配实战代码(一)
[leetcode] wild card matching
idea设置打开文件窗口个数
Uniapp + unicloud + Unipay realize wechat applet payment function
Multi table operation - Auto Association query
Mysql统计技巧:ON DUPLICATE KEY UPDATE用法
[yolov5.yaml parsing]
Wireless WiFi learning 8-channel transmitting remote control module
一次生产环境redis内存占用居高不下问题排查
pytorch-线性回归
【pytorch 修改预训练模型:实测加载预训练模型与模型随机初始化差别不大】
SET XACT_ABORT ON
【PyTorch预训练模型修改、增删特定层】
报错ModuleNotFoundError: No module named ‘cv2.aruco‘
【云原生 | Kubernetes篇】Ingress案例实战(十三)
Solve readobjectstart: expect {or N, but found n, error found in 1 byte of