How do i create an array that can hold multiple data types in GoLang?

Viewed 1889

While declaring an array or a slice I'm required to specify the type of data that I want to store in the array or list.

How do I make an array that can hold data of multiple types ?

1 Answers

You can do something like this mixedArray := []interface{}{"astring", 10, &Object{'hello'}}

Most likely the values that you want to hold share some behavior, in that case what you should really do is create an interface and simply make the array content type that interface.

Related