Inspectopedia
 
2024.3

'for..in' is used instead of 'for..of'

Info
Code Style
New
Last modified: 03 December 2024

Reports a usage of a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in">for..in</a> loop on an array. Suggests replacing it with a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of">for..of</a> loop.

for..of loops, which are introduced in ECMAScript 6, iterate over iterable objects. For arrays, this structure is preferable to for..in, because it works only with array values but not with array object's properties.