DEV Community

Discussion on: TC39 proposal: Array.lastItem

Collapse
 
healeycodes profile image
Andrew Healey

Array.first and Array.last are interesting proposals. Thanks for the clear examples. I've always thought Python's [-1] accessor for the last element was very elegant.

Collapse
 
tombarr profile image
Thomas Barrasso

Thanks for the kind words. I'm mixed on negative indices. They are more powerful than a single Array.last property because they let you easily access say, the second to last element [-2]. But I don't find them that much clearer.

That said, JavaScript will likely never get support for negative indices because Array is just an Object, and [-1] is a valid property on either. This would introduce a break change to the language (although it's a pretty bad idea using an Array as a map).