Home>Article>Backend Development> Can golang map delete elements?
#Map is a built-in type in Go that binds keys and values together. The corresponding value can be obtained by key.
How to create a map?
A map can be created by passing the types of keys and values to the built-in function make. (Recommended learning:go) The syntax of
is:
make(map[KeyType]ValueType)
(Translator’s Note: The type of map is represented as map[KeyType]ValueType) For example:
personSalary := make(map[string]int)
delete () function
delete () function is used to delete elements of the collection, and the parameters are map and its corresponding key. Examples are as follows:
package main import "fmt" func main() { m := map[string]int{ "a": 1, "b": 2, "c": 3, } fmt.Println("Deleting values") name, ok := m["a"] fmt.Println(name,ok) delete(m,"a") name,ok = m["a"] fmt.Println(name,ok) }
The above is the detailed content of Can golang map delete elements?. For more information, please follow other related articles on the PHP Chinese website!