notexOPENOverview
Notex/Languages/Emptying a Map
01.24LESSON 24 OF 33 · 1 MIN READ

Emptying a Map

Always free to read

The clear function that you saw in “Emptying a Slice” works on maps also. A cleared map has its length set to zero, unlike a cleared slice. The following code:

m := map[string]int{
    "hello": 5,
    "world": 10,
}
fmt.Println(m, len(m))
clear(m)
fmt.Println(m, len(m))

prints out:

map[hello:5 world:10] 2
map[] 0
Progress is saved on this device.
KEEP EXPLORING

One note leads to another.

Back to the library →
⌕
Search across the entire library ⌘ K