简体   繁体   中英

How do I resolve the no-restricted-syntax from eslinter in JavaScript ?

I am using ESLint in my project and am using the airbnb style guide. The following piece of code in my program is giving me a linting issue. I am working on ES6. It's telling me to avoid using for-in here. What would be a better alternative as per ES6 standards ?

function solveRole (i18nData) {
  entries = {};

    for (const property in i18nData) {
    entries[property] = i18nData[property];
  }
}

There's no need to iterate over the keys using either a for-in loop or Object.keys(...).forEach as all you are doing is assigning all properties of one object to another.

Try this:

entries = Object.assign({}, i18nData)

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