Skip to content

Commit f149c51

Browse files
authored
Add an example for accessing the element index
Add an example using `Array.prototype.entries()` to access the element index in a `for...of` loop. Resolves #216
1 parent f012ee0 commit f149c51

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

docs/rules/array-foreach.md

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ for (const el of els) {
9292
}
9393
```
9494

95+
Use [`entries()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries) to get access to the index:
96+
```js
97+
for (const [i, el] of els.entries()) {
98+
els.name = `Element ${i}`
99+
}
100+
```
101+
95102
## Version
96103

97104
4.3.2

0 commit comments

Comments
 (0)