Thank you for the advice! It worked. On Friday, March 20, 2020 at 11:29:20 AM UTC+11, Ian Lance Taylor wrote: > > On Thu, Mar 19, 2020 at 5:21 PM <yvon...@outlook.com <javascript:>> > wrote: > > > > I have an array and the length of this array is dynamic. I want to pass > this array's values as a list of parameters to a function. Can you please > suggest what is a good way to do this? > > > > > > For example, func(query string, args ...interface{}). My array is > arrayExample := []string {"1", "a", "b", "2"}. Then it will be something > like func(query, arrayExample[0], arrayExample[1], arrayExample[2], > arrayExample[3]). > > > > If my array is arrayExample := []string {"1", "a"}. Then it will be > something like func(query, arrayExample[0], arrayExample[1]) > > > > But as I mentioned the array is dynamic so the length can be any number. > I can get the length, but how can I pass each member in the array to the > function call as a list of parameters? > > Note that what you are calling an array, Go calls a slice. > > Write this as `f(query, arrayExample...)`. See > https://golang.org/ref/spec#Passing_arguments_to_..._parameters . > > Ian >
-- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9ae48a29-afc7-4a9f-bb31-d8357c4b8ad8%40googlegroups.com.