DEV Community

Discussion on: `at` coming soon to ECMAScript

 
laurieontech profile image
Laurie

"Unfortunately, JS's language design makes this impossible. The [] syntax is not specific to Arrays and Strings; it applies to all objects. Referring to a value by index, like arr[1], actually just refers to the property of the object with the key "1", which is something that any object can have. So arr[-1] already "works" in today's code, but it returns the value of the "-1" property of the object, rather than returning an index counting back from the end."

github.com/tc39/proposal-relative-...

 
aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan

Oh, gotcha! So it would break existing code. Thanks for the reference!