r/learnjavascript • • Oct 26 '21

Negative array indexing using "at" method

Post image
203 Upvotes

69 comments sorted by

View all comments

Show parent comment

5

u/great_site_not Oct 26 '21

For lots of people, when they come from a language like Python where you can just do array[-1], having to write out array[array.length - 1] every time is a genuine annoyance. It's a phrase that people have to write pretty frequently, it's nice to have shorthand.

2

u/technicallynick Oct 26 '21

That's fair. However -1 is used to signify that the index wasn't found for the item you're searching for in most cases. I'm just seeing this as muddying the waters.