Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use for...of if possible instead of for index #4

Open
philipsens opened this issue May 14, 2024 · 1 comment
Open

Use for...of if possible instead of for index #4

philipsens opened this issue May 14, 2024 · 1 comment

Comments

@philipsens
Copy link
Member

The for...of statement can often be used instead of a C style for index.
The C style for should only be used if there isn't anything to iterate over. Like when you have a list of non-corresponding items or if there are a number of steps defined in a variable.

@Matthbo
Copy link
Member

Matthbo commented May 15, 2024

Add explanation about for..in too since either one can be used based on if you want the key or the value of an object or based on iterator type.

As explanation to why its better, we can take inspiration from eslint-unicorn/no-for-loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants