Quick actions

cmd+k|ctrl+k

Navigation

Languages

Maps / Delete from a map / Essential Go

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T09:40:15Z

Updated

2019-03-26T09:40:15Z

package main

import (
	"fmt"
)

func main() {
	people := map[string]int{"john": 30, "jane": 29}
	fmt.Printf("%v\n", people)

	// deleting a key that doesn't exist is a no-op
	delete(people, "notfound")
	fmt.Printf("%v\n", people)

	// deleting a key in nil map is a no-op
	var something map[string]int
	delete(something, "notfound")
}
INFO