【发布时间】:2021-01-05 00:40:45
【问题描述】:
const async = require('async');
const arr = [
{ name: 'john', id: '1' },
{ name: 'Andrie', id: '2' }]
let collectArr = [];
let data = async.mapLimit(arr, 5, async function (input) {
collectArr.push({ name: input.name, id: input.id });
return collectArr;
})
data.then((result) =>{
console.log('success',result);
}).catch(e => console.log('err'));
因此,我在这里向 async.mapLimit 提供数组,而无需回调并在这里期待承诺。 预期输出:- [ { name: 'john', id: '1' }, { name: 'Andrie', id: '2' } ] ,
得到结果:-
[ [ { name: 'john', id: '1' }, { name: 'Andrie', id: '2' } ], [{名称:'约翰',id:'1'},{名称:'Andrie',id:'2'}]]
所以我的问题是它为什么要创建多个数组副本,如何处理?
【问题讨论】:
标签: javascript node.js asynchronous async-await async.js