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
+8.8k Golang : Executing and evaluating nested loop in html template
+6.1k Golang : Grab news article text and use NLP to get each paragraph's sentences
+37.7k Golang : Comparing date or timestamp
+14k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+16.3k Golang : convert string or integer to big.Int type
+21.2k Golang : Clean up null characters from input data
+9k Golang : Get SPF and DMARC from email headers to fight spam
+51.9k Golang : How to get time in milliseconds?
+31.7k Golang : How to convert(cast) string to IP address?
+6.8k Get Facebook friends working in same company
+7.2k CloudFlare : Another way to get visitor's real IP address