How should guard-for-in, be modified when eslint reports an error?

 for (const i in this.keywords) {
        count += this.keywords[i].list.length;
      }
 The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype guard-for-in

how should this be modified?

Jul.06,2021

using loops to for in objects will include properties inherited through the prototype chain. This behavior may result in unexpected items in the for loop.

for (key in foo) {
    doSomething(key);
}

Rule details
this rule is designed to prevent unexpected behavior that can occur when a loop is used if for in does not Filter the results in the loop. Therefore, when the for in loop does not use the if statement to Filter its results, it issues a warning.

the following modes are considered a problem:

/*eslint guard-for-in: 2*/

for (key in foo) {    /*error The body of a for-in should be wrapped in an if statement to filter     unwanted properties from the prototype.*/
    doSomething(key);
}

the following modes are not considered a problem:

/*eslint guard-for-in: 2*/

for (key in foo) {
    if ({}.hasOwnProperty.call(foo, key)) {
        doSomething(key);
    }
}

Lou Zhu this seems to be traversing the this.keywords array. If the
array traverses, of course, you can also use for-of, to traverse the properties of the object
, but for-in can only be used to traverse the properties of the object, because the array is actually a special object, so it can also access its elements through properties, but such access will bring unexpected problems, so the subject, think about what you want to traverse in the end?
change it to:

for (i in this.keywords) {
  if(this.keywords.hasOwnProperty(i)){ //, 
    count += this.keywords[i].list.length;
  }
}

A better solution introduction to teacher Ruan Yifeng's ES6

for (i of this.keywords) {
  count += this.keywords[i].list.length;
}

on the other hand, you can also start with eslint and disable checking, but in fact, this is contrary to using eslint, so I suggest writing code that conforms to eslint rules, forming good habits, and being able to troubleshoot some problems while writing.

Menu