Standard library / reflect

reflect.Value.MapKeys()

Returns map keys in unspecified order. Use order-independent checks unless explicitly sorting keys. Expected stdout: '1 a\n'.

Formal Syntax & Structure

go syntaxgo
func (v Value) MapKeys() []Value

Return Value

[]Value

Returns map keys in unspecified order.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() {  m := reflect.ValueOf(map[string]int{"a": 7})  fmt.Println(len(m.MapKeys()), m.MapKeys()[0].String())}
Go Reference