[Solved] How to convert a map to a slice of entries?


package main

import "fmt"

func main() {
    //create a map
    m := map[int64]int64{512: 8, 513: 9, 234: 9, 392: 0}

    //create a slice to hold required values
    s := make([][]int64, 0)

    //range over map `m` to append to slice `s`
    for k, v := range m {

        // append each element, with a new slice []int64{k, v}
        s = append(s, []int64{k, v})
    }

    fmt.Println(s)
}

0

solved How to convert a map to a slice of entries?