简体   繁体   中英

Eslint error when using the for in loop how to restructure

I am getting 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 error when using the following line of code

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

How can I restructure the code to remove this error Thanks

Try this:

let errors = {};

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM