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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.