patterngoCritical
Delete key in map
Viewed 0 times
keydeletemap
Problem
I have a map:
How do I delete
That didn't work.
Update (November 2011):
The special syntax for deleting map entries is removed in Go version 1:
Go 1 will remove the special map assignment and introduce a new built-in function,
var sessions = map[string] chan int{}How do I delete
sessions[key]? I tried:sessions[key] = nil,false;That didn't work.
Update (November 2011):
The special syntax for deleting map entries is removed in Go version 1:
Go 1 will remove the special map assignment and introduce a new built-in function,
delete: delete(m, x) will delete the map entry retrieved by the expression m[x]. ...Solution
Go introduced a
delete(map, key) function:package main
func main () {
var sessions = map[string] chan int{};
delete(sessions, "moo");
}Code Snippets
package main
func main () {
var sessions = map[string] chan int{};
delete(sessions, "moo");
}Context
Stack Overflow Q#1736014, score: 403
Revisions (0)
No revisions yet.