Standard library / reflect

reflect.Append()

Appends assignable values to a slice and returns the resulting slice; retain the result because its length and backing array may change. Expected stdout: '[1 2 3 4] 3\n'.

Formal Syntax & Structure

go syntaxgo
func Append(s Value, x ...Value) Value

Parameters & Attributes

NameTypeDescription
sValueDestination slice value.
x...ValueZero or more values assignable to the destination element type.

Return Value

Value

Appends assignable values to a slice and returns the resulting slice; retain the result because its length and backing array may change.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() {  s := reflect.ValueOf([]int{1, 2, 3})  r := reflect.Append(s, reflect.ValueOf(4))  fmt.Println(r.Interface(), s.Len())}
Go Reference