2

I am try to create a map of string slice with the code in GO

newMap := map [string][]string{
    "first" : {
        "good", "bad"
    },
    "second" : {
        "top", "bottom"
    }
}

It seems not to be the right way, what is the wrong with it?

1 Answer 1

5

You have to add a comma , at the end of each initializer list.

newMap := map [string][]string{
    "first" : {
        "good", "bad",
    },
    "second" : {
        "top", "bottom",
    },
}

You can find a working example here.

Sign up to request clarification or add additional context in comments.

3 Comments

@Intermernet Thanks! I used your code but with slightly changes.
what a meaningless comma, especially in the slice !
I actually find this comma really convenient as it allows adding/removing/commenting out map/slice elements in the same way no matter whether they are in the middle or at the end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.