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

for ... of ... vs .forEach #35

Open
ccouzens opened this issue Jun 22, 2021 · 1 comment
Open

for ... of ... vs .forEach #35

ccouzens opened this issue Jun 22, 2021 · 1 comment

Comments

@ccouzens
Copy link
Contributor

Do we have a preference for if we use:

const array = [1, 2, 3, 4];

for (const item of array) {
  console.log(item);
}

// or

array.forEach((item) => {
  console.log(item);
});

There is an eslint plugin that enforces a style. The arguments are quite one-sided, but I agree with it.

I was inspired to ask by this bit of code
https://github.com/loveholidays/aurora/blob/3a5223d3680c35c5a494f3526e14f728a018d416/src/apis/content-repository/ContentRepositoryApi.ts#L155

@dios-david
Copy link
Contributor

dios-david commented Jun 22, 2021

Personally I don't see an issue with having both, but if I had to pick only one then I would keep .forEach

I think this is more like an imperative vs declarative argument, I vote for declarative

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