Is there a way to get a list of all the keys in a Go language map? The number of elements is given by len()
, but if I have a map like:
m := map[string]string{ "key1":"val1", "key2":"val2" };
How do I iterate over all the keys?
dictionarygoloops
Is there a way to get a list of all the keys in a Go language map? The number of elements is given by len()
, but if I have a map like:
m := map[string]string{ "key1":"val1", "key2":"val2" };
How do I iterate over all the keys?
Best Answer
https://play.golang.org/p/JGZ7mN0-U-
or
Go language specs for
for
statements specifies that the first value is the key, the second variable is the value, but doesn't have to be present.