可能标题描述的不够明确,详细解释如下:
我有这样一个循环
var sizeList = []
imgs.forEach((item, index) => {
request({
url: item,
encoding: null
}, (err, res, body) => {
let buffer = body
sizeList.push(sizeOf(buffer))
console.log(sizeList)
})
})
console.log('全局', sizeList)
问题1:
console.log(sizeList)会逐渐打印出结果
[ { height: 202, width: 172, type: 'png' } ]
[ { height: 202, width: 172, type: 'png' },
{ height: 837, width: 750, type: 'png' } ]
[ { height: 202, width: 172, type: 'png' },
{ height: 837, width: 750, type: 'png' },
{ height: 837, width: 750, type: 'png' } ]
请问我如何直接获得最后的一次完整的数组结果,而不要逐次叠加循环的过程?
问题2:
console.log('全局', sizeList)目前得到的是空数组[]
如何使外部console.log('全局', sizeList)获取到循环的最终数组列表呢?
还望得到解答,谢谢!
待解决
悬赏分:10
- 离问题结束还有 90天12小时3分19秒
点赞 0反对 0举报 0
收藏 0
分享 0
