OneBite.Dev - Coding blog in a bite size

add new item in array in Go

Code snippet on how to add new item in array in Go

mySlice := []string{"apple", "banana"}
mySlice = append(mySlice, "kiwi")

This code snippet appends a new item to an array in Go. The array is defined as mySlice, starting with two elements “apple” and “banana”. The append function is then used to add an additional item “kiwi” to the array. The function takes two arguments - the original array and the new item to be added. The modified array is then saved back in the same variable mySlice.

go