I try to iterate over a FormData entries() object. ESlint is giving me error that I really shouldn't do it the way I have done below: 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 = '/');
}
However entries()
doesn't have forEach() so I can not use it.
What is a clean way to do the above?
Instead of using for..of
, spread the .entries()
iterator into an array so you can use forEach
on it:
[...data.entries()].forEach((row) => {
// ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.