How to declare an array in a struct in golang | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to declare an array in a struct in golang

I want a array in the struct ,how to do it? Okay,i tried .. type Model struct{ list []string } Is it correct way of declaring?

22nd May 2021, 6:05 AM
OfcourseitsRohit
OfcourseitsRohit - avatar
1 Answer
+ 1
Lucifer Correct. But if you want to create a object of this struct use this below declaration↓ func main(){ obj:=Modal{[]string{"item1", "item2"}} }
22nd May 2021, 7:17 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar