The for range Construct
This lesson explains how to use the for range construct to access key-value pairs in a map.
We'll cover the following...
Explanation #
The following construct can also be applied to maps:
for key, value := range map1 {
...
}
The key
is the key of the map, and the value
is the value for the key
. They are local variables only known in the body of the for statement.
If you are only interested in the values, use the form:
for _, value := range map1 {
fmt.Printf("Value is: %d\n", value)
}
To get only the keys, you can use:
...