Standard library / reflect
reflect.Value.Clear()
Deletes map entries or zeroes all elements in a slice, without changing its length. Expected stdout: '[0 0 0] 3\n'.
Formal Syntax & Structure
go syntaxgo
func (v Value) Clear()Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { s := reflect.ValueOf([]int{1, 2, 3}); s.Clear(); fmt.Println(s.Interface(), s.Len()) }