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 from our phone:

delete(contacts, "Gary")

If we call the delete function with a key that is not in the map nothing bad happens. Other languages may crash or throw an exception!

Let’s practice the delete operation and then we will review everything that we have learned.



First, let’s delete all the chocolate donuts.


Then print out the donuts map again after your delete statement.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?