The maps Package
maps.Keys and maps.Values return iterators and maps.Clone copies a map.
Example
package main
import (
"fmt"
"maps"
"slices"
)
func main() {
m := map[string]int{"a": 1, "b": 2}
keys := slices.Sorted(maps.Keys(m))
fmt.Println(keys)
c := maps.Clone(m)
c["z"] = 9
fmt.Println(len(m), len(c))
}Result
[a b] 2 3
Exercise
Copy a map.
maps.(m)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.