for-of statement of sparse array

Jason Orendorff jason.orendorff at
Thu Jul 5 16:04:52 PDT 2012

On Thu, Jul 5, 2012 at 12:54 PM, Brendan Eich <brendan at> wrote:
> Allen privately observed that Array forEach skips holes, matching for-in.
> That counts for a lot with me -- we have only a blind
> for(i=0;i<a.length;i++)... loop not skipping holes, but of course it
> wouldn't. That is weak precedent on which to build for-of.

In what sense is that precedent weak? It seems a stronger precedent
than forEach on every axis; arguably it's one of the most-trodden
cowpaths in programming, in any language.

for-in is a kind of anti-precedent, for array iteration.

> Map may win at some point, who knows? It's not winning if one wants
> an array, numeric indexing, .length, the usual prototype methods.

I agree Map is somewhat beside the point. TC39 should spec what's best
for developers net of everything. Even if that's matching for-in. But
the purpose of for-of is to address the shortcomings of for-in;
following it just for the sake of consistency would be self-defeating.


More information about the es-discuss mailing list