如何在不使用 for 循环的情况下迭代 FormDataentries() 数组

Cof*_*lic 2 javascript iteration eslint

我尝试迭代 FormData Entry() 对象。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.

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 = '/');
}
Run Code Online (Sandbox Code Playgroud)

但是entries()没有 forEach() 所以我不能使用它。

执行上述操作的干净方法是什么?

Cer*_*nce 7

不要使用for..of,而是将.entries()迭代器展开到一个数组中,以便您可以使用forEach它:

[...data.entries()].forEach((row) => {
  // ...
Run Code Online (Sandbox Code Playgroud)