How to create Map using the make function in Go?


A map value can also be initialized using the make function.

Example

package main

import "fmt"

func main() {
    var employee = make(map[string]int)
    employee["Mark"] = 10
    employee["Sandy"] = 20
    fmt.Println(employee)
    
    employeeList := make(map[string]int)
    employeeList["Mark"] = 10
    employeeList["Sandy"] = 20
    fmt.Println(employeeList)
}

Output

map[Mark:10 Sandy:20]
map[Sandy:20 Mark:10]
Most Helpful This Week