Skip to content

Go: How to Iterate Over All the Keys of a Map?

Iterating over the keys of a map in Golang is so easy and you can do it by using a for-range loop. The only difference is to get only the keys not the values:

package main

import "fmt"

func main() {
	myMap := map[string]string{
		"key #1": "value #1",
		"key #2": "value #2",
		"key #3": "value #3",

	for key := range myMap {

Leave a Reply

Your email address will not be published. Required fields are marked *