/golang

How to loop over map in GoLang

you can use builtn took range for it. Check the example;

import (
    "fmt"
)

func main() {
    kar := make(map[string]int)

    kar["puz"] = 66
    kar["pol"] = 99

    for i, v := range kar {
        fmt.Printf("key %d = value%d
", i, v)
    }
}

will log

key %!d(string=puz) | value 66
key %!d(string=pol) | value 99

[Process exited 0]

Subscribe to Necmettin Karakaya

Get the latest posts delivered right to your inbox

Necmettin Karakaya

Necmettin Karakaya

Full Stack Developer