当前位置:网站首页>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'
})
}
边栏推荐
- Solve the grpc connection problem. Dial succeeds with transientfailure
- Proof of the thinking of Hanoi Tower problem
- Programmers are involved and maintain industry competitiveness
- 石油化工企业安全生产智能化管控系统平台建设思考和建议
- redis 集群模式原理
- Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in
- 【load dataset】
- [crawler] bugs encountered by wasm
- redis的持久化机制原理
- 阻止浏览器后退操作
猜你喜欢

Redis master-slave mode

Thoughts and suggestions on the construction of intelligent management and control system platform for safe production in petrochemical enterprises

liunx禁ping 详解traceroute的不同用法

Cdga | six principles that data governance has to adhere to

Reading notes of growth hacker

Codeworks 5 questions per day (1700 average) - day 5

MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!
![[mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]](/img/1a/dd7453bc5afc6458334ea08aed7998.png)
[mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]
调查显示传统数据安全工具在60%情况下无法抵御勒索软件攻击

COMSOL -- three-dimensional graphics random drawing -- rotation
随机推荐
汉诺塔问题思路的证明
如何让你的产品越贵越好卖
MySQL statistical skills: on duplicate key update usage
【load dataset】
Web API配置自定义路由
2022年国内云管平台厂商哪家好?为什么?
一次生产环境redis内存占用居高不下问题排查
【上采样方式-OpenCV插值】
Hiengine: comparable to the local cloud native memory database engine
[mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]
[leetcode] wild card matching
多表操作-自关联查询
JS for循环 循环次数异常
[loss functions of L1, L2 and smooth L1]
Prevent browser backward operation
XML解析
iTOP-3568开发板NPU使用安装RKNN Toolkit Lite2
Application of a class of identities (vandermond convolution and hypergeometric functions)
2048 game logic
《增长黑客》阅读笔记