Source: medium.com

Golang Maps
how to create, update, delete and loop through golang maps A map is a builtin type in Go that is used to store key-value pairs, where each key is unique. all the individual keys needs to be a particular type and all the individual values of another type although the keys and values can be of different types.

The syntax for adding new items to a map is the same as that of arrays, if you try to add to maps which have not been initialised it will result in “panic: assignment to entry in nil map” lets create a function(printMap) below to loop through the values of a map which gets passed as reference.

Before retrieving a single value we want to check if that key-value exists in the map, below code show how to check and retrieve at the same time

Related Articles