Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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, …)



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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: