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 :
Advertisement
Something interesting
Tutorials
+17.5k Golang : Clone with pointer and modify value
+8.8k Golang : Accept any number of function arguments with three dots(...)
+9.2k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+13k Swift : Convert (cast) Int to String ?
+6.7k Golang : Derive cryptographic key from passwords with Argon2
+19.1k Golang : Display list of time zones with GMT
+7.4k Golang : Individual and total number of words counter example
+13.7k Golang : Tutorial on loading GOB and PEM files
+16.4k CodeIgniter/PHP : Create directory if does not exist example
+30.4k Golang : How to verify uploaded file is image or allowed file types
+7.9k Golang : Get today's weekday name and calculate target day distance example
+11.3k Golang : Intercept and process UNIX signals example