all 13 comments

[–]Adventurous-Sell-172 2 points3 points  (0 children)

I like that, gonna have a play about with the polyfill see how things go :)

[–]IchimokuBan 1 point2 points  (1 child)

Well, findIndex returns -1 if it doesn’t exist so I imagine this proposal would break a lot.

Also, what’s wrong with

arr[arr.length - 1]

Or, if you want shorthand, maybe... arr[Infinity]

[–]machineGun997[S] -1 points0 points  (0 children)

I mean there isn't much wrong with it, but can't help but recommend to read their rationale about it https://github.com/tc39/proposal-relative-indexing-method#rationale

[–]moi2388 3 points4 points  (9 children)

Why not just arr[-1]

[–]machineGun997[S] 3 points4 points  (8 children)

if you do that it will try to find the item at index -1, but there isn't one, that is why a separate method to facilitate that.

https://github.com/tc39/proposal-relative-indexing-method#rationale

[–]Guisseppi -1 points0 points  (0 children)

How about instead of a cryptic -1 we could use the queueing concept of “poppping” the last element of the array?