How to copy map in Go?

Technology CommunityCategory: GolangHow to copy map in Go?
VietMX Staff asked 3 years ago

You copy a map by traversing its keys. Unfortunately, this is the simplest way to copy a map in Go:

a := map[string]bool{"A": true, "B": true}
b := make(map[string]bool)
for key, value := range a {
	b[key] = value
}