Skip to content

xferion.com

Just another XFerion Europe site

Recent Posts

  • Hello world!
  • golang: Check if key exists in map
  • Golang: Reverse ISOWeek, get the date of the first day of ISO week
  • Golang: measure time to execute code
  • Golang create directory

Recent Comments

  1. A WordPress Commenter on Hello world!
  2. Abinhho on Building a Golang web application with Revel
  3. stephan on Golang substr or substring equivalent
  4. a-h on Golang substr or substring equivalent
  5. legends2k on Golang substr or substring equivalent

Archives

  • February 2022
  • July 2015
  • May 2015
  • February 2015
  • January 2015

Categories

  • Go Programming
  • Software Development
  • Uncategorized
  • Web Programming

Month: July 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
}

 

 

Posted on July 30, 2015Categories Go ProgrammingTags go, go code, Golang, kb, map, programmingLeave a comment on golang: Check if key exists in map
Proudly powered by WordPress
Cleantalk Pixel