frankframework / frontend-conventions

1 stars 0 forks source link

Prefer <some container>.forEach(...) over for(<initializer>; <condition>; <next>) #2

Closed mhdirkse closed 1 month ago

mhdirkse commented 1 month ago

During my development work on frank-config-layout, I made many errors with indexes starting at 0 or 1. Iterating with L.forEach(...) is much less error prone. You can have the index within the array as the second argument: L.forEach((v, i) => {... })

mhdirkse commented 1 month ago

If you think this is a useful addition, I can write this part if you like.

Matthbo commented 1 month ago

There are multiple ways to loop over an iterable, you can use for..in and for..of if you dont want to think about indices.

We also use linting rules that also give out errors on forEach usage, see their reasoning here