使用for in循环时的Eslint错误如何重构

时间:2020-05-15 13:15:18

标签: javascript reactjs

使用以下代码行时出现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错误

 const errors = {};
      for (const i of err.inner) {
        errors[i.path] = i.message;
      }

如何重组代码以消除此错误 谢谢

1 个答案:

答案 0 :(得分:1)

尝试一下:

let errors = {};

err.inner.forEach(item => {
   errors[item.path] =  item.message;
});