In golang is there a nice way of getting a slice of values from a map?

前端 未结 5 1930
小蘑菇
小蘑菇 2020-12-23 15:38

If I have a map m is there a better way of getting a slice of the values v then

package main
import (
  \"fmt\"
)

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


        
5条回答
  •  春和景丽
    2020-12-23 16:10

    Unfortunately, no. There is no builtin way to do this.

    As a side note, you can omit the capacity argument in your slice creation:

    v := make([]string, len(m))
    

    The capacity is implied to be the same as the length here.

提交回复
热议问题