Answers for "golang get last two elements of slice"

Go
2

golang get last element of slice

// Go doesn't have negative indexing like Python does.

a := []string{"A", "B", "C"}
s := a[len(a)-1] // C
Posted by: Guest on December-29-2021
-2

golang get last element of slice

sl = sl[:len(sl)-1]
Posted by: Guest on November-12-2020

Browse Popular Code Answers by Language