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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With