2808 explained code solutions for 75 technologies

golangHow to get values slice from map

package main

func main() {
  mp := make(map[string]string)

  mp["name"] = "Joe"
  mp["position"] = "president"
  vals := make([]string, 0, len(mp))
  for  _, v := range mp {
     vals = append(vals, v)
}ctrl + c
package main

default package declaration


initialize map with string keys and string values


returns length of a given map

vals = append(vals, v)

add each mp value to vals slice