Skip to content

Commit a6b6669

Browse files
authored
Merge pull request #241 from github/array-foreach-entries
Add an example for accessing the element index in a `for...of` loop
2 parents 6977d4e + 80d51fe commit a6b6669

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

docs/rules/array-foreach.md

Lines changed: 7 additions & 0 deletions
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+
el.name = `Element ${i}`
99+
}
100+
```
101+
95102
## Version
96103

97104
4.3.2

0 commit comments

Comments
 (0)