当前位置:网站首页>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 weight decay and dropout
- 互联网公司实习岗位选择与简易版职业发展规划
- Simply solve the problem that the node in the redis cluster cannot read data (error) moved
- 一类恒等式的应用(范德蒙德卷积与超几何函数)
- Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in
- redis主从中的Master自动选举之Sentinel哨兵机制
- 汉诺塔问题思路的证明
- 阻止瀏覽器後退操作
- Multi table operation - Auto Association query
猜你喜欢
随机推荐
yolov5目標檢測神經網絡——損失函數計算原理
全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
[configuration method of win11 multi-user simultaneous login remote desktop]
中非 钻石副石怎么镶嵌,才能既安全又好看?
项目总结笔记系列 wsTax KT Session2 代码分析
阻止浏览器后退操作
How does redis implement multiple zones?
c#操作xml文件
redis 集群模式原理
一次生产环境redis内存占用居高不下问题排查
Yolov5 target detection neural network -- calculation principle of loss function
Pytorch softmax regression
[singleshotmultiboxdetector (SSD, single step multi frame target detection)]
Vscode shortcut key
ibatis的动态sql
[crawler] bugs encountered by wasm
Mysql统计技巧:ON DUPLICATE KEY UPDATE用法
How to protect user privacy without password authentication?
Splunk configuration 163 mailbox alarm
Redis cluster (master-slave) brain crack and solution