Standard library / reflect
reflect.Value.Index()
Returns the indexed element of an array, slice or string; for a string the index selects a byte. Expected stdout: '2\n'.
Formal Syntax & Structure
go syntaxgo
func (v Value) Index(i int) ValueParameters & Attributes
| Name | Type | Description |
|---|---|---|
| i | int | Zero-based index, or the input interface value for TypeOf and ValueOf. |
Return Value
Value
Returns the indexed element of an array, slice or string; for a string the index selects a byte.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { s := reflect.ValueOf([]int{1, 2, 3}); fmt.Println(s.Index(1).Int()) }