Essential Go Maps  Edit on GitHub      File Issue

Count number of map entries

The built-in function len returns the number of elements in a map

m := map[string]int{}
len(m) // 0

m["foo"] = 1
len(m) // 1

If a variable points to a nil map, then len returns 0.

var m map[string]int
len(m) // 0
  ↑ ↓ to navigate     ↵ to select     Esc to close