如何判断Go中的地图值是否未定义? [重复]

This question already has an answer here:

Suppose I have a map like:

m := map[string]interface{}{}

Now I get a string "a", I want to know if there's value in m["a"], how can I tell?

As I can see now, m["a"] is never nil, so I can't compare it to nil to see if there's anything. Also, there's not a keyword named undefined to do that..

</div>

map access returns two values, the second one being a boolean telling you if there's a value.

You can use this standard idiom :

if elm, ok := m["a"]; ok {
    // there's an element
} else {
    // no element
} 

Documentation