Post

GoLangGoLang

J
James ROBERT

Posted on 25th April 2024|15 views

0
votes

Golang Iterate Over Map

How can I iterate over a map by using for loop in Golang?

Answers
P
Lakshmi sowjanya

Posted on 25th April 2024

You can refer this example:

package main

 import "fmt"

 func main() {

var employee = map[string]int{"Mahi": 100, "Rohit": 85,"Rahul": 80, "Hardhik": 70}

    for key, element := range employee {

        fmt.Println("Key:", key, "=>", "Element:", element)

    }

}

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos