tc39 / proposal-array-last

A JavaScript TC39 Proposal for getting the last element from an array
311 stars 13 forks source link

Simpler form #22

Closed absolux closed 5 years ago

absolux commented 5 years ago

What about simply use -1 as index

let arr = ['foo', 'bar', 'baz']

console.log(arr[-1]) // prints "baz"
keithamus commented 5 years ago

I'm afraid this wouldn't be possible due to that have existing behaviour today, which people - unfortunately - rely on. Right now code that uses that would return undefined and for that to change to a value would have a large potential to break the web.