Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Deleting Keys From Maps | Intro to Structs & Maps
Introduction to GoLang

Deleting Keys From MapsDeleting Keys From Maps

We can also remove key-value pairs from maps using the delete() function.

Here are some points to note regarding the delete() function:

  • The delete function does not return any value;
  • If the key keyName doesn't exist, it simply does nothing;
  • If the map mapName doesn't exist, it shows an error during compilation.

Here is an example of the delete() function being used in a program:

go

index.go

question-icon

Considering the map code below, which of the expressions will execute without compilation errors:

Select a few correct answers

Everything was clear?

Section 6. Chapter 7
course content

Course Content

Introduction to GoLang

Deleting Keys From MapsDeleting Keys From Maps

We can also remove key-value pairs from maps using the delete() function.

Here are some points to note regarding the delete() function:

  • The delete function does not return any value;
  • If the key keyName doesn't exist, it simply does nothing;
  • If the map mapName doesn't exist, it shows an error during compilation.

Here is an example of the delete() function being used in a program:

go

index.go

question-icon

Considering the map code below, which of the expressions will execute without compilation errors:

Select a few correct answers

Everything was clear?

Section 6. Chapter 7
some-alt