All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S4138.html Maven / Gradle / Ivy

There is a newer version: 10.17.0.28100
Show newest version

Why is this an issue?

for...of statements are used to iterate over the values of an iterable object. Iterables are objects implementing the @@iterator method, which returns an object conforming to the iterator protocol. JavaScript provides many built-in iterables that can and should be used with this looping statement.

The use of the for...of statement is recommended over the for statement when iterating through iterable objects as simplifies the syntax and eliminates the need for a counter variable.

const arr = [4, 3, 2, 1];

for (let i = 0; i < arr.length; i++) {  // Noncompliant: arr is an iterable object
  console.log(arr[i]);
}

When looping over an iterable, use the for...of for better readability.

const arr = [4, 3, 2, 1];

for (let value of arr) {
  console.log(value);
}

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy