Get slices of keys and values from a map

yourbasic.org/golang

You can use a range statement to extract slices of keys and values from a map.

keys := make([]keyType, 0, len(myMap))
values := make([]valueType, 0, len(myMap))

for k, v := range myMap {
	keys = append(keys, k)
	values = append(values, v)
}

Further reading

Maps explained [code example]