Go Maps
Lesson 1 of 1
  1. 1
    Think of a list of contacts on a phone. We can search by name to find the associated phone number. In programming, we often need to connect one data piece with another. This association is what map…
  2. 2
    In Go, there are two ways to create a map. We’ll be covering both in this exercise. #### Creating a map with make We can use the make function to create an empty map. The format is: variableNam…
  3. 3
    Maps make it easy to look up values and store the value in a variable for further use: variable := yourMap[keyValue] But what happens if we never added the requested key-value pair to the map bu…
  4. 4
    Maps are also easy to add key-value pairs or to change the value of an existing pair. In both cases we specify the map name, the key, and the value: yourMap[newKey] = newValue So to add a new cu…
  5. 5
    Sometimes we have a key that we no longer need in our map. Go allows us to remove elements using the delete function: delete(yourMap, keyValueToDelete) Let’s say we want to remove a contact …
  6. 6
    In this lesson, we have introduced concepts and syntax related to using maps in our Go programs. Let’s take a moment to review what we’ve learned. #### Map Creation Maps can be initialized wit…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo