26 lines
504 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
If you have an iterable, such as an array, set, or list, your best option for looping through its values is the ``++for of++`` syntax. Use a counter, and ... well you'll get the right behavior, but your code just isn't as clean or clear.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
const arr = [4, 3, 2, 1];
for (let i = 0; i < arr.length; i++) { // Noncompliant
console.log(arr[i]);
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
const arr = [4, 3, 2, 1];
for (let value of arr) {
console.log(value);
}
----