reflect.MapIndex() Function in Golang with Examples Last Updated : 03 May, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.MapIndex() Function in Golang is used to get the value associated with key in the map v. To access this function, one needs to imports the reflect package in the program. Syntax: func (v Value) MapIndex(key Value) Value Parameters: This function does not accept any parameter. Return Value: This function returns the value associated with key in the map v. Below examples illustrate the use of the above method in Golang: Example 1: C // Golang program to illustrate // reflect.MapIndex() Function package main import ( "fmt" "reflect" ) func main() { test := map[string]interface{}{"First": "firstValue"} Pass(test) } // Main function func Pass(d interface{}) { mydata := reflect.ValueOf(d).MapIndex(reflect.ValueOf("First")) fmt.Printf("Value: %+v \n", mydata.Interface()) fmt.Printf("Kind: %+v \n", mydata.Kind()) fmt.Printf("Kind2: %+v \n", reflect.ValueOf(mydata.Interface()).Kind()) } Output: Value: firstValue Kind: interface Kind2: string Example 2: C // Golang program to illustrate // reflect.MapIndex() Function package main import ( "fmt" "reflect" ) type Test struct { Data string } func (t Test) GetData() string { return t.Data } type Stringer interface { GetData() string } // Main function func main() { d := map[string]Stringer{"Geeks": Test{Data: "Null"}} mydata := reflect.ValueOf(d).MapIndex(reflect.ValueOf("Geeks")) fmt.Println(reflect.ValueOf(mydata.Interface())) } Output: {Null} Comment More infoAdvertise with us Next Article reflect.MapIndex() Function in Golang with Examples S SHUBHAMSINGH10 Follow Improve Article Tags : Go Language Golang-reflect Similar Reads reflect.Index() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Index() Function in Golang is used to get the v's i'th element. To access this function, one needs to imports the 2 min read reflect.Kind() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Kind() Function in Golang is used to find the name of kind. To access this function, one needs to imports the ref 2 min read reflect.MapKeys() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.MapKeys() Function in Golang is used to get a slice containing all the keys present in the map, in unspecified or 2 min read reflect.MapOf() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.MapOf() Function in Golang is used to get the map type with the given key and element types, i.e., if k represent 1 min read reflect.Pointer() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Pointer() Function in Golang is used to get the v's value as a uintptr. To access this function, one needs to imp 2 min read Like