I use the following code that works as expected, while using a ESLINT i got error
ESLint: iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations. (no-restricted-syntax)
This is the code
for (const subscription of resp.data.subscriptions) {
if (subscription.url) {
return subscription.url;
}
}
The code is simply
Is there a way to write it better to avoid the eslint issue ?
There is a debate about for...of usage here and its eventual restriction
for(let i = 0; i < array.length; i ++) { ... }is antiquated syntax, and while I know everyone understands what it means, we should be leaving it behind.
array.maphas functional connotations and we shouldn't be producing side effects in the closure.
array.forEachis an option, but I personally don't like it for this sort of imperative work.So I think the ForOfStatement should be removed from the restricted syntax for the above reasons - anyone with any conflicting viewpoints? Do we know what the original justification is?
for..of is more expensive than forEach, check this out
I have no opinions, you could just remove the eslint rule
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With