Answers for "golang array is interface"

Go
1

interface to array golang

func test(t interface{}) {
    switch reflect.TypeOf(t).Kind() {
    case reflect.Slice:
        s := reflect.ValueOf(t)

        for i := 0; i < s.Len(); i++ {
            fmt.Println(s.Index(i))
        }
    }
}
Posted by: Guest on August-08-2020

Browse Popular Code Answers by Language