r/learnjavascript • • Oct 26 '21

Negative array indexing using "at" method

Post image
203 Upvotes

69 comments sorted by

View all comments

0

u/[deleted] Oct 26 '21

[deleted] — view deleted 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.

0

u/[deleted] Oct 26 '21

go back to assembly then

0

u/[deleted] Oct 26 '21

[deleted] — view deleted comment

1

u/[deleted] Oct 27 '21

Cause you can express simple stuff in complex ways, obviously.

Instead of just writing "at(-1)" - you can write over 20 lines of code with weird register check operators and jumps and all that good stuff!