DEV Community

Discussion on: `at` coming soon to ECMAScript

Collapse
 
stegriff profile image
Ste Griffiths

The article covers this really:

Well, as it turns out, -1 is already a valid key. Arrays are really objects with indices as keys. So arr[-1] is looking at the arr object and the value of the "-1" key, which is undefined.

There can be a "-1" key present in the object, so the behaviour for "negative indices" is already defined by the language.