Standard library / reflect
reflect.Value.Field()
Return the direct field at an index in a struct value. Incorrect kind or out-of-range index panics. Expected stdout: '7\n'.
Formal Syntax & Structure
go syntaxgo
func (v Value) Field(i int) ValueParameters & Attributes
| Name | Type | Description |
|---|---|---|
| i | int | Zero-based index, or the input interface value for TypeOf and ValueOf. |
Return Value
Value
Return the direct field at an index in a struct value.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { v := reflect.ValueOf(struct{ X int }{7}); fmt.Println(v.Field(0).Int()) }