当前位置:网站首页>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
- 871. Minimum Number of Refueling Stops
- Mysql统计技巧:ON DUPLICATE KEY UPDATE用法
- Cdga | six principles that data governance has to adhere to
- [untitled]
- Web API配置自定义路由
- 【PyTorch预训练模型修改、增删特定层】
- Unity Xlua MonoProxy Mono代理类
- 【Win11 多用户同时登录远程桌面配置方法】
- Is it difficult to apply for a job after graduation? "Hundreds of days and tens of millions" online recruitment activities to solve your problems
猜你喜欢

【使用TensorRT通过ONNX部署Pytorch项目】

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

iTOP-3568开发板NPU使用安装RKNN Toolkit Lite2

Multi table operation - sub query

pytorch-softmax回归

XML解析

Liunx prohibit Ping explain the different usage of traceroute

Redis cluster (master-slave) brain crack and solution

Harbor image warehouse construction

【L1、L2、smooth L1三类损失函数】
随机推荐
How to get a token from tokenstream based on Lucene 3.5.0
Dynamic SQL of ibatis
[crawler] Charles unknown error
阻止瀏覽器後退操作
[yolov5.yaml parsing]
12.(地图数据篇)cesium城市建筑物贴图
Codeforces Round #804 (Div. 2)
Open3D 网格(曲面)赋色
Redirection of redis cluster
Web API配置自定义路由
Mongodb replica set
Ncp1342 chip substitute pn8213 65W gallium nitride charger scheme
无线WIFI学习型8路发射遥控模块
abap查表程序
【云原生 | Kubernetes篇】Ingress案例实战(十三)
Principle of redis cluster mode
pytorch-权重衰退(weight decay)和丢弃法(dropout)
【SingleShotMultiBoxDetector(SSD,单步多框目标检测)】
简单解决redis cluster中从节点读取不了数据(error) MOVED
Simply solve the problem that the node in the redis cluster cannot read data (error) moved