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
What is the default HTTP server in Go?
Use Field Tags in the Definition of Struct Type
Is There Still a Need for Programming in This AI World?
How do you handle HTTP client caching in Go?
Convert Float32 to Float64 and Float64 to Float32
Golang program to demonstrates how to encode map data into a JSON string.