for-of statement of sparse array

Jason Orendorff jason.orendorff at gmail.com
Thu Jul 5 16:10:29 PDT 2012


On Thu, Jul 5, 2012 at 2:09 PM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>> Map may win at some point, who knows? It's not winning if one wants an array, numeric indexing, .length, the usual prototype methods.
>
> We could consider also have "dense" interators available:
>
>      for (let v of array.denseValues) console.log(v);

This makes sense to me, but most arrays are meant to be dense in
practice. So perhaps it makes more sense to add methods specifically
for sparse arrays, making developers type more characters in the rare
case rather than the common case:

    for (let v of array.sparseValues()) ...;
    for (let [i, v] of array.sparseItems()) ...;

-j


More information about the es-discuss mailing list