How to copy a map to another map?
To copy a map content need to execute a for loop and fetch the index value 1 by 1 with element and assign it to another map. Below is a short example.
Example
package main
import (
"fmt"
)
func main() {
map1 := map[string]int{
"x":1,
"y":2,
}
map2 := map[string]int{}
/* Copy Content from Map1 to Map2*/
for index,element := range map1{
map2[index] = element
}
for index,element := range map2{
fmt.Println(index,"=>",element)
}
}
Output
x => 1
y => 2
Most Helpful This Week
Data encryption with AES-GCM
How to Remove duplicate values from Slice?
Regular expression to extract text between square brackets
Convert specific UTC date time to PST, HST, MST and SGT
Encoding and Decoding using json.Marshal and json.Unmarshal
Example to use Weekday and YearDay function
How to set timeout for http.Get() requests in Golang?
Replace first occurrence of string using Regexp
How to rotate an image?
How to delete or remove element from a Map?