Copy a map

suggest change

In Go, every assignment copies the value.

A map value is a small header that points at the buckets. Assigning a map, or passing it to a function, copies that header. Both variables share the same buckets, so a write through one is visible through the other.

Copy the entries when you need an independent map:

	src := make(map[string]int)
	src["one"] = 1
	src["two"] = 2

	dst := make(map[string]int)

	for key, value := range src {
		dst[key] = value
	}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents