reflect.MapKeys() Function in Golang with Examples Last Updated : 03 May, 2020 Comments Improve Suggest changes 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.MapKeys() Function in Golang is used to get a slice containing all the keys present in the map, in unspecified order. To access this function, one needs to imports the reflect package in the program. Syntax: func (v Value) MapKeys() []Value Parameters: This function does not accept any parameter. Return Value: This function returns a slice containing all the keys present in the map, in unspecified order. Below examples illustrate the use of above method in Golang: Example 1: C // Golang program to illustrate // reflect.MapKeys() Function package main import ( "fmt" "reflect" ) // Main function func main() { key := 10 value := "Geeksforgeeks" mapType := reflect.MapOf(reflect.TypeOf(key), reflect.TypeOf(value)) mapValue := reflect.MakeMap(mapType) mapValue.SetMapIndex(reflect.ValueOf(key), reflect.ValueOf(value)) keys := mapValue.MapKeys() fmt.Println(keys) } Output: [<int Value>] Example 2: C // Golang program to illustrate // reflect.MapKeys() Function package main import ( "fmt" "reflect" ) // Main function func main() { key := 1 value := "abc" mapType := reflect.MapOf(reflect.TypeOf(key), reflect.TypeOf(value)) mapValue := reflect.MakeMap(mapType) mapValue.SetMapIndex(reflect.ValueOf(key), reflect.ValueOf(value)) mapValue.SetMapIndex(reflect.ValueOf(2), reflect.ValueOf("def")) mapValue.SetMapIndex(reflect.ValueOf(3), reflect.ValueOf("gh")) keys := mapValue.MapKeys() for _, k := range keys { c_key := k.Convert(mapValue.Type().Key()) c_value := mapValue.MapIndex(c_key) fmt.Println("key :", c_key, " value:", c_value) } } Output: key : 1 value: abc key : 2 value: def key : 3 value: gh Comment More infoAdvertise with us Next Article reflect.MapKeys() Function in Golang with Examples S SHUBHAMSINGH10 Follow Improve Article Tags : Go Language Golang-reflect Similar Reads reflect.MakeMap() 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.MakeMap() Function in Golang is used to create a new map with the specified type. To access this function, one nee 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.MakeSlice() 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.MakeSlice() Function in Golang is used to create new zero-initialized slice value for the specified slice type, le 2 min read reflect.MapIndex() 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.MapIndex() Function in Golang is used to get the value associated with key in the map v. To access this function, 2 min read reflect.MakeFunc() 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.MakeFunc() Function in Golang is used to get the new function of the given Type that wraps the function fn. To acc 2 min read reflect.MakeChan() 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.MakeChan() Function in Golang is used to create a new channel with the specified type and buffer size. To access 2 min read reflect.New() 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.New() Function in Golang is used to get the Value representing a pointer to a new zero value for the specified typ 2 min read reflect.Len() 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.Len() Function in Golang is used to get the v's length. To access this function, one needs to imports the reflect 1 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.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