From 3e0c0a8add600cd395c4e30a4db8cc1ede90acc9 Mon Sep 17 00:00:00 2001
From: Robert Griesemer m
, it can be discovered using the
built-in function len(m)
-and may change during execution. Elements may be added and removed
-during execution using special forms of assignment;
-and they may be accessed with index expressions.
+and may change during execution. Elements may be added during execution
+using assignments and retrieved with
+index expressions; they may be removed with the
+delete
built-in function.
A new, empty map value is made using the built-in
@@ -2431,21 +2432,6 @@ where the result of the index expression is a pair of values with types
a[x]
as in the single-result form.
-Similarly, if an assignment to a map element has the special form -
- --a[x] = v, ok -- -
-and boolean ok
has the value false
,
-the entry for key x
is deleted from the map; if
-ok
is true
, the construct acts like
-a regular assignment to an element of the map.
-
Assigning to an element of a nil
map causes a
run-time panic.
@@ -4738,6 +4724,27 @@ n2 := copy(s, s[2:]) // n2 == 4, s == []int{2, 3, 4, 5, 4, 5}
n3 := copy(b, "Hello, World!") // n3 == 5, b == []byte("Hello")
+
+
+The built-in function delete
removes the element with key
+k
from a map m
. The
+type of k
must be assignable
+to the key type of m
.
+
+delete(m, k) // remove element m[k] from map m ++ +
+If the element m[k]
does not exist, delete
is
+a no-op. Calling delete
with a nil map causes a
+run-time panic.
+