ValyriA
ValyriA

Reputation: 157

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];
  }
}

Upvotes: 6

Views: 10421

Answers (1)

sdgluck
sdgluck

Reputation: 27217

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:

const entries = Object.assign({}, i18nData)

Upvotes: 9

Related Questions