Lesson 19. The ever-versatile map

After reading lesson 19, you’ll be able to

  • Use maps as collections for unstructured data
  • Declare, access, and iterate over maps
  • Explore some uses of the versatile map type

Maps come in handy when you’re searching for something, and we’re not just talking about Google Maps (www.google.com/mars/). Go provides a map collection with keys that map to values. Whereas arrays and slices are indexed by sequential integers, map keys can be nearly any type.

Note

This collection goes by several different names: dictionaries in Python, hashes in Ruby, and objects in JavaScript. Associative arrays in PHP and tables in Lua serve as both maps and conventional arrays.

Maps are especially useful for ...

Get Get Programming with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.