Skip to content

Commit

Permalink
Merge pull request #241 from github/array-foreach-entries
Browse files Browse the repository at this point in the history
Add an example for accessing the element index in a `for...of` loop
  • Loading branch information
srt32 committed May 2, 2022
2 parents 6977d4e + 80d51fe commit a6b6669
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/rules/array-foreach.md
Expand Up @@ -92,6 +92,13 @@ for (const el of els) {
}
```

Use [`entries()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries) to get access to the index:
```js
for (const [i, el] of els.entries()) {
el.name = `Element ${i}`
}
```

## Version

4.3.2

0 comments on commit a6b6669

Please sign in to comment.