In Go, to find the keys of a map, you can use the range
keyword to iterate over the map, and the for ... range ...
loop syntax. Within the loop, you can access the keys of the map.
Here's an example:
main.go153 chars8 lines
Output:
main.go6 chars4 lines
In this example, we create a map with key-value pairs "a": 1, "b": 2, "c": 3. Then, we use the for ... range ...
loop to iterate over the map, and assign the key to the variable key
. Each time through the loop, we print the value of key
, which will be the keys of the map.
gistlibby LogSnag