Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Accessing Map Values
course content

Course Content

Introduction to GoLang

Accessing Map ValuesAccessing Map Values

We can access the value corresponding to a key in a map using the following syntax:

go

index.go

For example:

go

index.go

The expression prices["apple"] essentially references the memory location where the value 100 is stored; hence, it acts like a variable. Therefore, we can edit the value stored at that key using the = operator:

go

index.go

We can use the same assignment syntax to create a new key in the map:

If the provided keyName doesn't exist in the map, it will create and add a new key to the map with the assigned value.

go

index.go

question-icon

What will be the output of the following code?

Select the correct answer

Everything was clear?

Section 6. Chapter 6
some-alt