July 30, 2015

golang: Check if key exists in map

You can easily check if a key exists in a go map by using the ok result:


value, ok := myMap[key]

Or in an one line check:


if val, ok := myMap[key]; ok {
// do something
}

 

 

Leave a Reply

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

XFerion Europe LLP
We build an maintain your software. From web to mobile. From MVP to extended product. Contact us if you wish to discuss a project.
CONTACT US