Golang builtin.delete() function example

package builtin

The delete built-in function deletes the element with the specified key (m[key]) from the map. If m is nil or there is no such element, delete is a no-op.

Golang builtin.delete() function usage example

 package main

 import "fmt"

 type Person struct {
 Age int
 }

 var personmap map[string]Person

 func main() {
 personmap = make(map[string]Person)

 personmap["Adam"] = Person{36}

 fmt.Println("Before delete : ", personmap)

 delete(personmap, "Adam")

 fmt.Println("After delete : ", personmap)

 }

Output :

Before delete : map[Adam:{36}]

After delete : map[]

Reference :

http://golang.org/pkg/builtin/#delete

Advertisement