News for hackers. Stuff that matters.
Re:A Reintroduction to JavaScript by jarek-foksa on Tuesday February 04, 2014 @05:29AM (#7176584)
As of ES6 I would limit myself to only three styles of writing array for-loops:

1. Crockford's C style with cached array length (fast and flexible, but verbose):

  for (let index = 0, length = array.length; index < length; index += 1) {
    console.log(index, array[index]);
  }
2. Functional style (terse and flexible, but slow):

  array.forEach((value, index) => console.log(index, value));
3. Python style (fast and terse, but not flexible):

  for (let value of array) {
    console.log(value);
  }
By "flexible" I mean being able to e.g. iterate over items with odd indexes or in reverse direction.

There are no comments on this comment yet.