首页 > 解决方案 > 陷入 eslint 错误,即单独地,应避免循环以支持数组迭代

问题描述

我有一些迭代的代码,它运行良好。安装 eslint 后,我​​的代码之一由 eslint 生成错误。

我的代码是:

for (const column of columns) {
    for (const slugname of result[column.name]) {
        const alphabet = slugname.slugname;
        if (total[alphabet]) {
            total[alphabet] += column.value;
        } else {
            total[alphabet] = column.value;
        }
    }
}

eslint 生成一个错误,就是这个

error 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 no-restricted-syntax

任何帮助或建议都非常感谢。据我说代码写得很精确而且很小,不知道eslint错误的线索

标签: javascriptecmascript-6eslinteslint-config-airbnb

解决方案


columns.map(x => result[x.name].map((y) => {
  const alphabet = y.slugname;
  if (total[alphabet]) {
      total[alphabet] += x.value;
    } else {
      total[alphabet] = x.value;
    }
    return true;
}));

推荐阅读