Created
July 12, 2018 15:51
-
-
Save hi-manshu/f36df18ae36764d21c09c34fbf4bb50c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| func main() { | |
| //Declared a map userData using the keyword `make` | |
| var userData = make(map[int]string) | |
| //prints the default map | |
| fmt.Println(userData) | |
| //adds a element at the 0th key | |
| userData[0] = "Himanshu" | |
| fmt.Println(userData) | |
| //adds a element at the 1th key | |
| userData[1] = "Singh" | |
| //prints the new map | |
| fmt.Println(userData) | |
| //extracts the value to a variable using the key | |
| var firstName = userData[0] | |
| fmt.Println(firstName) | |
| //prints the lenght of the map | |
| fmt.Println(len(userData)) | |
| //delete is called to delete any value at a particular key | |
| delete(userData, 0) | |
| fmt.Println(userData) | |
| } | |
| >>go run mapExample.go | |
| >>map[] | |
| >>map[0:Himanshu] | |
| >>map[1:Singh 0:Himanshu] | |
| >>Himanshu | |
| >>2 | |
| >>map[1:Singh] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment