判斷方式為value,ok := map[key], ok為true則存在
package main
import "fmt"
func main() {
demo := map[string]bool{
"a": false,
}
//錯誤,a存在,但是傳回false
fmt.Println(demo["a"])
//正确判斷方法
_, ok := demo["a"]
fmt.Println(ok)
}
輸出
false
true