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
Illustration of Producer Consumer Problem in Golang
Various examples of printing and formatting in Golang
How To Make an HTTP Server in Golang?
GO Program to Check Whether a Number is Even or Odd
Create and Print Multi Dimensional Slice in Golang
What is risk management and why is it important?
Example of Interface with Type Embedding and Method Overriding in GO language
How do you handle HTTP client caching in Go?
How do you handle HTTP errors in Go?
Interface embedding another interface in Go Programming Language