Negative indices for arrays

Ash Berlin ash_js at firemirror.com
Thu Nov 11 11:39:48 PST 2010


On 11 Nov 2010, at 19:30, Dmitry A. Soshnikov wrote:
> OTOH, negative indices, are even not array indices. I.e.
> 
> var a = [1,2];
> a[-1] = 0;
> print(a); // 1,2
> print(a.length); // 2
> 
> From this viewpoint -- for what are they? Seems again, `-n` notations for arrays and strings is useful as a "from the end"-sugar. So now I may propose it.


Yes please, both perl and ruby have it and I often find myself instinctively typing it in JS.

-ash


More information about the es-discuss mailing list