2022-02-04 16:28:24 +00:00

39 lines
735 B
Plaintext

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.
== Noncompliant Code Example
[source,javascript]
----
const arr = [4, 3, 2, 1];
for (let i = 0; i < arr.length; i++) { // Noncompliant
console.log(arr[i]);
}
----
== Compliant Solution
[source,javascript]
----
const arr = [4, 3, 2, 1];
for (let value of arr) {
console.log(value);
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]