Home>

As the title

Is it possible to insert an associative array map into

slice?

Is it possible to return a map for the return blood of func?

I tried it myself

too many arguments in call to


I was angry.

func write_review () {
    fmt.Println ("title depression")
    reviews: = map [string] string {}
    reviews ["title"] = input ()
    fmt.Println ("genre depression")
    reviews ["genre"] = input ()
    fmt.Println ("Depression")
    reviews ["review"] = input ()
    fmt.Println (reviews)
    fmt.Printf ("% T", reviews)
// return reviews or var sli = append (sli, reviews)
}
go
  • Answer # 1

    func write_review () map [string] string {
        return map [string] string {}
    }


    Then you can return a map type value.

    var slice [] map [string] string
    slice = append (slice, map [string] string {})


    You can add a map type value to the slice by writing as above.

Related articles