这是代码片段。我想访问每个内部的 imagePath 数组。...const imagePath=[]; req.files.images.forEach(async (image) => { let extName = path.extname(image.name); var dest = path.join(__dirname, '..', 'public', 'images', 'items'); var imgPath = await saveFile(image, dest, itemName, extName); imagePath.push(imgPath); // this line})...
1 回答

慕村225694
TA贡献1880条经验 获得超4个赞
通常,imagePath
可以在循环中轻松访问forEach
。
但是,您的forEach
回调是异步的。如果在循环console.log(imagePath)
之后立即执行 a forEach
,您将得到一个空数组。
一个简单的解决方法是使用for
…in
循环。
添加回答
举报
0/150
提交
取消