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
How to create an empty Slice in Golang?
Go program to reading plain text files
GO Program to Calculate Sum of Natural Numbers Using for.....Loop
Golang read json file into struct
Invalid memory address or nil pointer dereference error in Golang
Implementing Multiple Interfaces in Go Programming Language
Creating Instances of Struct Types
Sierpinski Carpet in Go Programming Language
Golang program for implementation of Linear Search
Declaration of a struct type