[英]How to iterate over a FormData entries() array without using for-loop
我嘗試遍歷 FormData 條目()對象。 ESlint 給了我一個錯誤,我真的不應該像下面那樣做: iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.
iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.
for (const row of data.entries()) {
const search = row[0].replace('internal_', '');
if (search.length > 0 && search.substr(1, 3) !== 'ext') {
currentCTX.data[search][2] = row[1];
}
const currentData = JSON.stringify(currentCTX.data);
const { feedId } = window;
const params = { userSave: currentData, id: parseInt(feedId, 10), channel: 'import' };
const res = fetchData(`${apiUrl}mapping`, params).then(() => window.location = '/');
}
但是entries()
沒有 forEach() 所以我不能使用它。
執行上述操作的干凈方法是什么?
不使用for..of
,而是將.entries()
迭代器擴展到一個數組中,以便您可以在其上使用forEach
:
[...data.entries()].forEach((row) => {
// ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.