Re:FP techniques that will help you write better JavaScript
by feupan on Friday February 11, 2022 @08:57AM
(#30301524)
for (const [index, value] of array.entries()) {}
It is longer than:
array.forEach((value, index) => {})
… but forEach has too many limitations (no exits, no await, …)
Re:FP techniques that will help you write better JavaScript
by gear54rus on Saturday February 12, 2022 @03:55AM
(#30311172)
oh yeah, destructuring's nice
I'll give you await (gotta use awkward reduce there) but if you want exit, you're better off with something like `find`
Another advantage is that array functions better convey what are you trying to do with this particular operation.
ForEach does get you both.
I don't remember using for loop for at least 3 years previously as a frontend engineer :)