All thoughts and posts are my own, said by @rakibtg.
posted at Wednesday, 4 April 2018
In Go language associative array have made easier than I have thought.
This is going to be a quick article that demonstrates how we can use Associative Array in Go language.

In Go, we call Associative Array a "map". Which seems to be confusing because the keyword map works differently in other languages! However, now we know that map is some kind of Associative Array in Go.

Let's make a map then,

1. Define an empty map(Associative Array)
To define an empty map we need to tell Go what would be the data type for both key and value pairs. Our first map would contain string as the key and also going to contain string as their value. Lets create the empty map now.

ourMap := make( map[ string ] string )

From the above line of code you will notice that we have defined the type for the key to string and as well as the type for value to string! Kinda cool right?

What is make()? We use "make" to preallocate space for a new map.

2. Add new properties
Now we can start to add some values as if it is an associative array like this,

ourMap[ "name" ] = "rakibtg"
ourMap[ "age" ]    = "20"

Wopsy! The age property contains 20 as a string because we said it too.

3. Print the entire array
To get all values simple print the map,

fmt.Println( ourMap )

4. Get value of a key
Let say we want to get the name,

fmt.Println( ourMap[ "name" ] )

5. Count items
To count how many elements/properties a map has use the len function.

fmt.Println( len( ourMap ) )

6. Delete an element
Deleting any element from a map requires its key name.

delete( ourMap, "age" )


Go have fun!