What is the Go
way for extracting the last element of a slice
?
var slice []int
slice = append(slice, 2)
slice = append(slice, 7)
slice[len(slice)-1:][0] // Retrieves the last element
The solution above works, but seems awkward.
转载于:https://stackoverflow.com/questions/22535775/the-last-element-of-a-slice