Learn
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.
Instructions
1.
First, let’s delete
all the chocolate
donuts.
2.
Then print out the donuts map again after your delete statement.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.