Another way to change the data in a slice is by re-slicing it, which removes the last element:
threeArr := []int{1, 4, 6}
// Remove last element:
threeArr = threeArr[:len(threeArr)-1]
// threeArr is now {1, 4}
// Remove last element again:
threeArr = threeArr[:len(threeArr)-1]
// threeArr is now {1}
Assignment
Follow the Coding Tutorial and let's play with some arrays.
Hint
Look at the examples above if you get stuck.
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
