Go if _,ok:=range map; Ok Check whether the key is in the map

Golang does not provide a method to determine whether an item is in an array. If such a method is frequently used in the program, the array can be converted into a map with the members of the array as keys, and then the above method can be used to determine the item. This will improve the judgment efficiency.

if _, ok := map[key]; ok {  

Leave a Reply

Your email address will not be published. Required fields are marked *