Home > Software design >  Return empty array from map instead of array with empty string
Return empty array from map instead of array with empty string

Time:04-06

I have a map of ids that map to an array of strings as such accountIDs := make(map[int64][]string, 0) and in my response this looks like:

"AccountIDs": {
    "1": [
        "19565",
        "21423"
    ],
    "7": [
        ""
    ]
}

How can I return an empty array instead of an array of empty string?

CodePudding user response:

Set the value to []string{}.

myMap[7] = []string{}

See Playground

  •  Tags:  
  • go
  • Related