How to change slice item value in Golang?


To change the value of a specific item, refer to the index number.

Example

package main

import "fmt"

func main() {
	var strSlice = []string{"India", "Canada", "Japan"}
	fmt.Println(strSlice)

	strSlice[2] = "Germany"
	fmt.Println(strSlice)
}

Output

[India Canada Japan]
[India Canada Germany]
Most Helpful This Week