tl;dr arr[len(arr)] is wrong; arr[len(arr)-1] is right because Go uses zero-based indexes like a bunch of other languages.
this post was submitted on 16 Jul 2026
4 points (70.0% liked)
Golang
2711 readers
4 users here now
This is a community dedicated to the go programming language.
Useful Links:
Rules:
- Posts must be relevant to Go
- No NSFW content
- No hate speech, bigotry, etc
- Try to keep discussions on topic
- No spam of tools/companies/advertisements
- It’s OK to post your own stuff part of the time, but the primary use of the community should not be self-promotion.
founded 3 years ago
MODERATORS
This is a thinly veiled advertisement.
tl;dr: The length of a slice is not a valid index into that slice.
Of course. Because Go uses zero-based indexing, just like many other languages.