Built-in function
Go delete()
Removes the entry for a key from a map. A missing key or nil map is a no-op. It does not return the removed value; read that value first if needed. Example prints false 1.
Formal Syntax & Structure
go syntaxgo
delete(m, key)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| m | map | Map to update. |
| key | assignable key type | Entry to remove. |
Working Example
Example Snippetgo
package main
import "fmt"
func main() { m := map[string]int{"a": 1, "b": 2} delete(m, "a") _, ok := m["a"] fmt.Println(ok, len(m))}