Hello everybody.
I've been wondering for some time if there couldn't be a way to index arrays
from the last element directly. Currently if you have an array lost in a deep
objects hierarchy, you have to refer to it twice, once to access the array
itself, and once again to access its length:
var lastItem =
myObject.anArray[ myObject.anArray.length - 1 ];
myObject.anArray[ myObject.anArray.length - 2 ] = "foo";
As it seems hard to change the core language to be able to access stuff with
negative indexes, the idea would be just to add a method to ease getting /
setting of items based on the length of the array:
//get the last element, same as .last( 0 )
var lastItem = myObject.anArray.last();
//set the ( length - 2 ) element
myObject.anArray.last( 1, "foo" );
It can also be implemented with current UAs.
Regards,
Jordan Osete
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss