Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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];
  }
}
like image 381
ValyriA Avatar asked Feb 07 '23 06:02

ValyriA


1 Answers

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)
like image 177
sdgluck Avatar answered Feb 09 '23 01:02

sdgluck