3 ms·
for is awkward in JS because you get either keys or values and not both ForEach does get you both. I don't remember using for loop for at least 3 years previo
by gear54rus 5y ago
for is awkward in JS because you get either keys or values and not both
ForEach does get you both.
I don't remember using for loop for at least 3 years previously as a frontend engineer :)
- feupan 5y agofor (const [index, value] of array.entries()) {} It is longer than: array.forEach((value, index) => {}) … but forEach has too many limitations (no exits, no await, …)
- gear54rus 5y agooh 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.