Standard library / reflect
reflect.Value.Slice()
Returns a slice view between an inclusive lower index and exclusive upper index, sharing underlying storage. Expected stdout: '[2 3]\n'.
Formal Syntax & Structure
go syntaxgo
func (v Value) Slice(i, j int) ValueParameters & Attributes
| Name | Type | Description |
|---|---|---|
| i | int | Zero-based index, or the input interface value for TypeOf and ValueOf. |
| j | int | Exclusive upper index. |
Return Value
Value
Returns a slice view between an inclusive lower index and exclusive upper index, sharing underlying storage.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { s := reflect.ValueOf([]int{1, 2, 3}); fmt.Println(s.Slice(1, 3).Interface()) }