简体   繁体   中英

How to fix eslint errors in javascript code

    for (const [key, value] of Object.entries(attrs)) {
      element.setAttribute(`${key}`, `${value}`);
    }
  }

I am using this in my code which is used to select the key values of keyboard but some errors are shown by 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

As @dork correctly pointed out in his comment, ( eslint suggests) you should not use for... of loops. It is not supported in old browsers and may require a polyfill ( regenerator-runtime ).

Better write your code this way:

Object.entries(attrs).forEach(([key, value]) => element.setAttribute(key, value));

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