JavaScript’s Array.prototype.forEach
is usually significantly slower than a for
loop. This is because forEach
includes extra checks that a for
loop normally doesn’t have. Are there any cases where a forEach
loop works (because of these checks) where a for
loop doesn’t?
To be clear, I am not asking why for
is faster than forEach
. I am asking if the extra checks in forEach
are ever useful.