I'm trying to return a string array from a function, but it is printing only the last index position value. Here is my code and output.
package main
import (
"fmt"
)
func main() {
myquote := varFunc("Go", "Bunny", "Let's", "Change", "ourself")
fmt.Println("here also:", myquote)
}
func varFunc(s ...string) string {
fmt.Println(s)
fmt.Printf("%T
", s)
quote := ""
for _, v := range s {
quote = v
fmt.Println("init: ", quote)
}
fmt.Println("is there: ", quote)
return quote
}
Playground: https://play.golang.org/p/jyZDL5oPmcz
My output:
[Go Bunny Let's Change ourself]
[]string
init: Go
init: Bunny
init: Let's
init: Change
init: ourself
is there: ourself
here also: ourself
Program exited.