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) Value

Parameters & Attributes

NameTypeDescription
iintZero-based index, or the input interface value for TypeOf and ValueOf.
jintExclusive 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()) }
Go Reference