MAPS in go :=

it is data structure used in go. Data collection is unordered pairs of KEY-VALUE. It’s also known as a hash map, hash table, unordered map, dictionary, or associative array.
Mapas son una estructura de colleccion de datos en base de pares en go. Los datos de par en par se guardan a traves de LLAVES (key) y VALORES (Value). Tambien llamados como diccionarios, tablas de hash, etc

Here is some features of Maps explained with a tiny code
Aqui con un simple ejemplo veamos algunas caracteristicas de los Mapas,

  • create a MAP syntax
  • display any data from MAP
  • add new Data to MAP
  • delete some Data from MAP
  • display number of element that MAP contains
package main

import "fmt"

func main() {
	//[KEY data type] VALUE Data type and all between {map structure come here }
	// you can also use MAKE function to initialization of map like myMap := make(map[string]int{}) 
	myMap := map[string]int{
		//KEY: VALUE and comma end of the declaration
		"zero": 0,
		"one":  1,
		// DO NOT FORGET also after last declaration comes comma ","
		"two": 2,
	}

	//Display VALUE of some data
	fmt.Println("Displaying only VALUE of one element in MAP -->", myMap["zero"])

	//Display all Map
	fmt.Println("Displaying entere MAP -->", myMap)

        //Display number of elements of  Map 
        fmt.Println("Displaying number of elements in Map -->", len(myMap))

	// add new element to the Map
	myMap["three"] = 3
	fmt.Println("Adding some new element to Map-->", myMap)

	//delete some element of MAP
	delete(myMap, "three")
	fmt.Println("Display after Deleting some Data from MAP-->", myMap)

}

play with an example

 

Some useful info about MAPS :

Arrays can be assigned as a Key in Maps but Slices NOT
– Los arrays pueden integrar un Map como Key per Slices NO !

Indexing of Maps is unordered, you can not call by index number but KEY name you can make it
– Indexado de los Maps es NO ORDENADO, se puede acceder por medio de KEY nombre de KEY no por [0] , [1] o [2]… etc

If you check if some Key exist in Maps misspelling Key you will get Value as 0 (zero) is Value 0 or Key does not exist you can check it with ok operator –> here is a example
– Si buscamos algún integrante en el Map atreves de KEY tenemos el resultado pero si buscamos un KEY que no existe vamos a seguir recibiendo un Valor 0 eso significa que es un valor o simplemente no existe en el Map eso lo podemos consultar a través de operador ok –> aquí un ejemplo

package main

import "fmt"

func main() {

	intCode := map[string]int{

		"USA":     1,
		"GERMANY": 49,
		"SPAIN":   34,
	}
	_, ok := intCode["FRANCE"]
	fmt.Println(ok)
}