Go TutorialLesson 18Free preview
Go Maps
This lesson is part of Go · All levels
Summary
This lesson is about maps, a set of key-value pairs with key types that should be comparable. The map is created with make(map[kunci]value) or directly with literal, and then accessed via a key such as m["a"]. Since the map is a reference type, changes to the contents are immediately visible; use delete() to delete entries and the comma-ok to check the presence of the key.
Key points
- Map is declared with map[Key]value and initialized make or literal
- The key must be comparable; the value must be of any type
- Delete(m, k) delete entries and len(m) count the number of entries
- M[k] returns a zero value when the key is not present; check with v, ok:= m[k]
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.