“我正在尝试根据异步操作从数组对象中跳过一个对象。我尝试了以下方法,但出现了类型错误。
尝试的方法1”
错误
尝试的方法1”
newObjectArray = await Promise.all(objectAray.reduce(async (result, el) => {
const asyncResult = await someAsyncTask(el);
if (asyncResult) {
result.push(newSavedFile);
}
return result;
}, []));
尝试了方法2
newObjectArray = await Promise.all(objectAray.reduce(async (prevPromise, el) => {
const collection = await prevPromise;
const asyncResult = await someAsyncTask(el);
if (asyncResult) {
prevPromise.push(newSavedFile);
}
collection.push(newSavedFile);
return collection;
}, Promise.resolve([])));
错误
'TypeError: #<Promise> is not iterable',
' at Function.all (<anonymous>)',